SharePoint 2010:在列表之间复制文档

时间:2010-07-06 13:47:12

标签: c# sharepoint-2010

以编程方式将所有文档从一个sharepoint文档列表复制到另一个文档列表的最佳方法是什么?

1 个答案:

答案 0 :(得分:2)

找到解决方案:

            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());
            }