0

I have the following console application, which moved some folders from one document library to another within the same SP 2013 site collection:-

 SPList sourceomslist = omsWeb.Lists.TryGetList("Order Management");
                        ;
   foreach (SPListItem currentItem in sourceomslist.Items)
          {

            if (currentItem["Status"].ToString() == "Closed")
                {

                             if (currentItem.ContentType.Name.ToLower().Contains("project"))
                       {
                         Console.WriteLine(currentItem["ID"]);
                         SPFolder folder = omsWeb.GetFolder(omsWeb.ServerRelativeUrl + "/Shared Documents/"+currentItem["ID"].ToString() );
                         folder.MoveTo(omsWeb.ServerRelativeUrl + "/ArchDocs/"+currentItem["ID"].ToString() );

                       }
               }

         }

now the MoveTo will preserve the metadata for the sub-folders and files, but it will reset the metadata for the roots folders that are been moved. So can anyone advice if i can force the MoveTo method to preserve the metadata data for the root folders that are been moved?

Thanks

2
+50

You need update folder metadata for the root folders after run the MoveTo method, modify the code as below.

if (currentItem.ContentType.Name.ToLower().Contains("project"))
{
    Console.WriteLine(currentItem["ID"]);
    SPFolder folder = omsWeb.GetFolder(omsWeb.ServerRelativeUrl + "/Shared Documents/"+currentItem["ID"].ToString());
    var modified = folder.Item["Modified"];
    var created = folder.Item["Created"];    
    folder.MoveTo(omsWeb.ServerRelativeUrl + "/ArchDocs/" + currentItem["ID"].ToString());
    SPFolder tfolder = omsWeb.GetFolder(omsWeb.ServerRelativeUrl + "/ArchDocs/" + currentItem["ID"].ToString());
    tfolder.Item["Created"] = created;
    tfolder.Item["Modified"] = modified;
    tfolder.Item.UpdateOverwriteVersion();
}
| 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.