我有一个如下的图书馆:
List
---------Folder 1
---------File 0
---------File 1
-----------------Folder 2
------------------------File 2
------------------------File 3
---------Folder 3
-----------------File 4
-----------------File 5
计划是将它复制到另一个库,我找到了一种方法来复制文件0 /文件1.但我正在寻找一种方法将所有库(带有子文件夹和文件的文件夹)复制到我的其他图书馆。
要复制文件,我这样做了:
SPListItem item = oldLib.GetItemById(collItem[i].ID);
byte[] fileBytes = item.File.OpenBinary();
string destUrl = newlib.RootFolder.Url + "/" + item.File.Name;
SPFile destFile = newlib.RootFolder.Files.Add(destUrl, fileBytes, true);
我是否想念一个简单的方法来做我想要的事情?
祝你好运
答案 0 :(得分:0)
SPList sourceLibrary = web.Lists["SourceLibraryName"];
SPFolderCollection subFolders = sourceLibrary.RootFolder.SubFolders;
foreach (SPFolder subFolder in subFolders)
{
if (subFolder.SubFolders.Count == 0)
{
Console.WriteLine(subFolder.Name + " have no subfolders inside");
//**Proceed with copying files
}
else
{
Console.WriteLine("*******"+subFolder.Name + " have subfolders inside*******");
foreach (SPFolder subSubFolder in subFolder.SubFolders)
{
Console.WriteLine(subFolder.Name);
//**Do the same as above
}
}
}
Console.ReadKey();