views:

26

answers:

1

What is the best way to copy all documents from one sharepoint document list to another programmatically?

A: 

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