Sharepoint - How to move documents from one library to other

If you want to do it through workflow then you can do it through SPD

http://www.documentmanagementworkflowinfo.com/sample-sharepoint-workflows/sharepoint-designer-workflow-move-document-one-library-next.htm

If you also want to copy history, then use following URL

http://vspug.com/dez/2007/11/30/moving-copying-documents-between-libraries-with-metadata-including-version-history/
http://blogulous.wordpress.com/2008/02/20/copying-documents-between-sharepoint-libraries-keeping-version-history-part-1/
http://sphelpdesk.spaces.live.com/blog/cns!D9676F3678CF7BE7!173.entry

By normal code :

To Move files from one location to another, use one of the MoveTo()methods of the SPFile class.

public void Movefiles(destlibUrl)
{
SPWeb web = SPContext.Current.Web;
SPFolder oFolder = web.GetFolder(“Source Library”);
SPFileCollection collFile = oFolder.Files;

//Copy the files to a generic List of type SPFile
List listFiles = new List(collFile.Count);

foreach (SPFile oFile in collFile)
{
listFiles.Add(oFile);
}

// Enumerate the List and move the files into the Destination library.
foreach (SPFile moveFile in listFiles)
{
moveFile.MoveTo(“destlibUrl/” + moveFile.Name, true);
}
}

You can also have a look at already solved solutions for your requirement.

http://geek.hubkey.com/2007/12/move-sharepoint-document-library-files.html?m=1

https://jgvimalan.wordpress.com/2010/09/27/programmatically-move-items-from-one-document-library-to-another/

http://www.learningsharepoint.com/2010/07/04/programmatically-copy-and-move-documents-in-sharepoint-2010/


You can use the Information Management Policy feature in Library A. You would add the retention policy to the content types you have included in Library A (Documents, for example) and set the expiry for 2 months. Once the document 'expires', you can transfer it to another location.

In order for this to work, you will need the Content Organizer feature on your site enabled, and use the submission point (which is the Content Organizer Drop off Library) as your transfer location within the policy. You can then set up a rule within the content organizer to direct everything in the drop off library to Library B.

Tags: