SharePoint 2010: Copy documents between lists
What is the best way to copy all documents from one sharep开发者_JS百科oint document list to another programmatically?
Found a solution:
SPDocumentLibrary fromList = (SPDocumentLibrary)SPContext.Current.Site.RootWeb.Lists.TryGetList(ListNames.DocmentListName);
SPWeb currentWeb = SPContext.Current.Web;
SPDocumentLibrary toList = (SPDocumentLibrary)currentWeb.Lists.TryGetList(ListNames.DocmentListName);
SPFileCollection collection = fromList.RootFolder.Files;
foreach (SPFile item in collection)
{
toList.RootFolder.Files.Add(item.Url, item.OpenBinary());
}
精彩评论