private void bFolder_Click(object sender, EventArgs e)
{
TreeNode currentNode = trvContent.SelectedNode;
SPObjectData objectData = (SPObjectData)currentNode.Tag;
using (SPWeb TopLevelWeb = objectData.Web)
{
dwnEachWeb(TopLevelWeb);
}
}
private void dwnEachWeb(SPWeb TopLevelWeb)
{
if (TopLevelWeb.Webs.Count == 0)
{
dwnEachList(TopLevelWeb);
}
foreach (SPWeb ChildWeb in TopLevelWeb.Webs)
{
dwnEachWeb(ChildWeb);
ChildWeb.Dispose();
}
}
private void dwnEachList(SPWeb oWeb)
{
if (oWeb.Lists.Count != 0)
{
foreach (SPList oList in oWeb.Lists)
{
if (oList.ItemCount != 0 && oList.Title != "Master Page Gallery")
{
dwnEachFolder(oList.RootFolder);
}
}
}
}
private void dwnEachFolder(SPFolder oFolder)
{
if (oFolder.SubFolders.Count == 0)
{
dwnEachFile(oFolder);
}
foreach(SPFolder SubFolder in oFolder.SubFolders)
{
dwnEachFolder(SubFolder);
}
}
private void dwnEachFile(SPFolder oFolder)
{
if (oFolder.Files.Count != 0)
{
foreach(SPFile ofile in oFolder.Files)
{
if (CreateDirectoryStructure(tbDirectory.Text, ofile.Url))
{
var filepath = System.IO.Path.Combine(tbDirectory.Text, ofile.Url);
byte[] binFile = ofile.OpenBinary();
System.IO.FileStream fstream = System.IO.File.Create(filepath);
fstream.Write(binFile, 0, binFile.Length);
fstream.Close();
}
}
}
}
//creating directory
private bool CreateDirectoryStructure(string baseFolder, string filepath)
{
if (!Directory.Exists(baseFolder)) return false;
var paths = filepath.Split('/');
for (var i = 0; i < paths.Length - 1; i++)
{
baseFolder = System.IO.Path.Combine(baseFolder, paths[i]);
Directory.CreateDirectory(baseFolder);
}
return true;
}
代码有一个逻辑问题,试图调试,但涉及到代码行
foreach(SPFile ofile in oFolder.Files)
在方法dwnEachFile中,它只是从方法出来而没有说明任何问题而根本没有创建任何目录。但是,如果我将其悬停在SPF上,它会说,
sharepoint网站中的文件,可以是Web部件页面,也可以是 文档库或文件夹中的文件。
答案 0 :(得分:0)