none
c# CSOM how to retain original modified by user info RRS feed

  • Question

  • Hi:

    Doing a migration of a lot of documents.  Wondering if there is a way to retain either the original modified by name when the c# code runs or trap the current logged in user and save that to modified by?  Currently have tried a few things and it seems to save the logged in user that the code is running under.  For example, if a user logs in as JaneDoe but the solution is running as devadmin, even though we look up the JaneDoe credentials and attempt to save them to the moved document editor field it seems to always update modified by with the user running the solution, in this case devadmin.

    Is there a way to preserve the existing modified by?

    Thank you

    Chuck

    Sunday, April 23, 2017 10:28 AM

Answers

  • Hi Chuck,

    We can get the original modified by data and update it back when some user modify the list item.

    ClientContext ctx = new ClientContext("http://sp2013/sites/team");
    List list = ctx.Web.Lists.GetByTitle("CustomList3");
    ListItem item = list.GetItemById(1);  
    ctx.Load(item);  
    ctx.ExecuteQuery();
    
    User user = ctx.Web.EnsureUser("denguo\\test");
    ctx.Load(user);  
    ctx.ExecuteQuery();  
                 
    item["Editor"] = user.Id; 
    item.Update();  
    ctx.ExecuteQuery();

    More information:

    http://www.c-sharpcorner.com/code/2148/system-update-for-sharepoint-list-items-using-csom.aspx

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Proposed as answer by Abhijeet Thorat Tuesday, April 25, 2017 11:47 AM
    • Marked as answer by ChTraywick Friday, April 28, 2017 1:45 PM
    Tuesday, April 25, 2017 7:47 AM
    Moderator

All replies

  • Hi Ch,

    This is problem with custom code and can not migrate meta data properties like created by, Modified by etc.. We have third party tools like Sharegate and metalogix which migrate all data including meta data properties for document. You can use free version for 15 days.

    ----------------------------------------------------------------------------

    Thanks

    Lalith

    ----------------------------------------

    Please mark as Answer, if this post solves your issue


    Sunday, April 23, 2017 1:21 PM
  • Hi,

    Using custom code to do the migration can be challenging when it comes to retaining the out of the box properties like modified by. However depending on your implementation you may try out SPListItem.SystemUpdate to retain the modified by values.

    The best approach to go forward with the migration,if it is possible, in your scenario would be to check the Content DB detach and attach which will carry over all your documents as is. Else you will have to use third party providers like ShareGate/Metalogix that can take care of retaining the metadata during migration.

    Thanks,

    Priyan


    Please Up Vote and Mark this as Answer if it helps.

    Monday, April 24, 2017 8:45 AM
  • Thank you. 
    Monday, April 24, 2017 8:48 AM
  • Thank you, will take a look.  Worst case maybe we can write the contents of modified by to a table with the location of the document(s) and later on run a server side utility that changes the modified by.

    Appreciate the help

    Chuck

    Monday, April 24, 2017 8:49 AM
  • Hi ChTraywick

    I landed on the post Update Created by & Modified by column in document library  which can help you if you are using server side code. 

    Cheers

    Reshmee


    Monday, April 24, 2017 1:27 PM
  • Hi Chuck,

    We can get the original modified by data and update it back when some user modify the list item.

    ClientContext ctx = new ClientContext("http://sp2013/sites/team");
    List list = ctx.Web.Lists.GetByTitle("CustomList3");
    ListItem item = list.GetItemById(1);  
    ctx.Load(item);  
    ctx.ExecuteQuery();
    
    User user = ctx.Web.EnsureUser("denguo\\test");
    ctx.Load(user);  
    ctx.ExecuteQuery();  
                 
    item["Editor"] = user.Id; 
    item.Update();  
    ctx.ExecuteQuery();

    More information:

    http://www.c-sharpcorner.com/code/2148/system-update-for-sharepoint-list-items-using-csom.aspx

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Proposed as answer by Abhijeet Thorat Tuesday, April 25, 2017 11:47 AM
    • Marked as answer by ChTraywick Friday, April 28, 2017 1:45 PM
    Tuesday, April 25, 2017 7:47 AM
    Moderator
  • Thank you Dennis, trying this and will update the results.
    • Marked as answer by ChTraywick Friday, April 28, 2017 1:44 PM
    • Unmarked as answer by ChTraywick Friday, April 28, 2017 1:45 PM
    Friday, April 28, 2017 9:15 AM
  • Thank you Dennis.  In case anyone else has this, I had a lower execute that was taking the logged in value and over writing the modified by.

    Thank you :)  Appreciate it.

    Friday, April 28, 2017 1:46 PM