這是我的代碼,用於將源列表中的文件複製到目標。使用下面的代碼,我只能複製文件,但不能複製文件夾。關於如何複製這些文件夾中的文件夾和文件的任何想法?複製從源到目標的列表項時的文件夾
using (SPSite objSite = new SPSite(URL))
{
using (SPWeb objWeb = objSite.OpenWeb())
{
SPList objSourceList = null;
SPList objDestinationList = null;
try
{
objSourceList = objWeb.Lists["Source"];
}
catch(Exception ex)
{
Console.WriteLine("Error opening source list");
Console.WriteLine(ex.Message);
}
try
{
objDestinationList = objWeb.Lists["Destination"];
}
catch (Exception ex)
{
Console.WriteLine("Error opening destination list");
Console.WriteLine(ex.Message);
}
string ItemURL = string.Empty;
if (objSourceList != null && objDestinationList != null)
{
foreach (SPListItem objSourceItem in objSourceList.Items)
{
ItemURL = string.Format(@"{0}/Destination/{1}", objDestinationList.ParentWeb.Url, objSourceItem.Name);
objSourceItem.CopyTo(ItemURL);
objSourceItem.UnlinkFromCopySource();
}
}
}
}
感謝