0

We have an order management system inside our SharePoint on-premises 2013. and the system has the following 2 main list and library:-

  1. Custom list containing the order info.
  2. Document library. Where each order has a folder with its id containing the related documents.

now i want to write a console application, which moves all orders which have their status = closed, and their related folders and documents to new list and new library.

so can anyone advice how i can write such a console application? where i want the moved items and documents to preserved their metadata and versions (if possible)

0

It is possible to move documents from one document library to another library using server object model. Use the method MoveToof SPFile to move documents from source to destination. Refer this http://msdn.microsoft.com/en-us/library/ms468280.aspx.

Preserving the metadata

Make sure that source and destination libraries have same set of fields/content types. Before moving the data from source, read all field values include "Author", "Modified" etc and after the document is moved to destination, get the SPListItemobject associated with the SPFile object and update all field values and finally call SPListItem.SystemUpdate(false)

Reference URL thread :

https://sharepoint.stackexchange.com/a/91957/85808

Code sample to move:

static void Main(string[] args) 
{ 
using (SPSite site = newSPSite("http://serverName:1111/SitePages/Home.aspx")) 
{ 
using (SPWeb web = site.RootWeb) 
{ 
SPFileCollection collFile = web.GetFolder("Shared Documents").Files; 
int count = collFile.Count; 
while(count!=0) 
{ 
collFile[count-1].MoveTo("Destination Library/" + collFile[count-1].Name, true); 
count--; 
} 
} 
} 
} 
}

Reference :

https://www.c-sharpcorner.com/blogs/programmatically-move-the-files-from-one-document-library-to-another-library-in-sharepoint1  

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.