Can we update the values of "Created By", "Modified By" columns in SharePoint lists ?


Ofcourse, you can. Created By & Modified By columns are “Person or Goup” type columns. In SharePoint all the lists has these columns by default. You can’t update the values of these columns from UI. But, you can do it through SharePoint APIs.


I have created .NET windows based application to update the “created by” and “modified by” columns using SharePoint APIs. I am giving the sample code snippet below. 


/******** Code snippet for modifying the Created by and Modified by column values of a SharePoint List *******/


/******** Written in .Net Windows Based Application **********/


 


private void button3_Click(object sender, EventArgs e)


        {


            SPSite oSite = new SPSite(http://<SiteName>/);


            SPWeb oWeb = oSite.OpenWeb();


            SPList oList = oWeb.Lists[“TestCustomList”];


            SPListItemCollection oListCollection = oList.Items;


            foreach (SPListItem oListItem in oListCollection)


            {


                SPFieldUserValue oUser = new SPFieldUserValue(oWeb, oWeb.CurrentUser.ID, oWeb.CurrentUser.LoginName);


   // or you can hard code the value like this,


 SPFieldUserValue oUser = new SPFieldUserValue(oWeb, 14, “Sowmyan Soman”);


                oListItem[“Author”] = oUser;//created by column value = “14;#Sowmyan Soman”


                oListItem[“Editor”] = oUser;//modified by column value = “14;#Sowmyan Soman”               


                oListItem.Update();               


            }


          


            oWeb.Update();


         }


 


//alternate method


SPSite oSite = new SPSite(“http://<site URL>”);


SPWeb oWeb = oSite.OpenWeb();


SPList oList = oWeb.Lists[“TestDocLibrary”];


SPListItem oListItem = oList.Items.GetItemById(5);


oListItem[“Editor”] = oWeb.CurrentUser.ID; //”20;#Sowmyan”;


oListItem.Update(); 


 


Updated : November 13 – 2008


 


The above code will not update the “created by” column of document library type SharePoint lists. The above code (both) will work just fine for all the lists and even it will update the “Modified by” column in SharePoint document libraries. One of my MS colleagues Vedant has posted a work-around to accomplish this update and you can find it out here


 


If anyone one want to know how we can do this same functionality using Powershell (codename : Monad) please see Tedd’s post : http://blogs.msdn.com/tadd/archive/2008/05/22/updating-the-created-by-and-modified-by-columns-in-sharepoint-lists.aspx


 


Comments (40)

  1. SharePoint has more than ten out-of-the-box webservices which will provide lots of functionalities that

  2. Thinks Ever had the good old System Account show up as your author or editor, oops I mean &#8220;Created

  3. Entwicklung What you need to know about AllowUnsafeUpdates (Part 1) What you need to know about AllowUnsafeUpdates

  4. Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008)

  5. Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008)

  6. Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008

  7. Whenever we create a SharePoint site we will get a default list called &#8220;Tasks&#8221;. This is one

  8. Whenever we create a SharePoint site we will get a default list called &#8220;Tasks&#8221;. This is one

  9. Direkter Download: SPPD-100-2008-06-25 Behind the Scene – QIK Video Aktuell SharePointCommunityCamp September

  10. Direkter Download: SPPD-100-2008-06-25 Behind the Scene – QIK Video Aktuell SharePointCommunityCamp September

  11. Direkter Download: SPPD-100-2008-06-25 Behind the Scene – QIK Video Aktuell SharePointCommunityCamp September

  12. Dag says:

    When modifying views for a discussion list, the Created by column can only be edited to show Name or department etc. This is pointless because the only value allowed is the system account. Other columns can be edited to show a calculated value like [emailaddress from]. This value can be fetched from the element that is added to the list.

    Will the code that you have written here make it possible to add another value to the "created by"-field that shows as an example where the element is origining from.

    My problem is that we want to use Sharepoint as a substitute for public folders. This works great for emails sent to this list(discussion lists) from internal users. When sent from external users "the created by" shows only system account. When synchronizing this folder to outlook the message appears to be from the system account, and cannot be replied to(Thank you Microsoft). I want this system account to go away for discussions lists. The created by field should show the email-address from the sender.

    Is ths possible with this code, and where is it supposed to be added

  13. sowmyancs says:

    If the users are completely from outside, then we can’t update the created by column with that name. You will get an idea about a work-around to this concern from this post.

    http://blogs.msdn.com/sowmyancs/archive/2008/09/10/a-possible-usage-of-people-asmx-and-usergroup-asmx-and-lists-asmx.aspx.

    However atleast the domain should be detectable by the SharePoint. But in this situation, I think you have to maintain a custom column which will keep this information and use an event handler ItemAdded or ItemAdding to update that column with the current login user’s information.

    You can try to attach an event handler to the list (ItemAdded or ItemAdding) and then try to get the current user’s email ID and update it in the custom column. Let me know if this will work for you.

  14. arosoccer says:

    Does this approach also work for editing the "Author" field in Document Libraries. I can use this to edit in Lists fine, but when I run it with a Document Library nothing happens.

  15. arosoccer says:

    Also I tried your approach about renaming the file from your post "Programmatically rename a file inside a SharePoint document library" this renamed the document fine but the Author still wouldn’t change.

  16. sowmyancs says:

    Thanks much for noticing this…actually the sample code I have posted here is without testing it with the document library. I have tested it out and saw the behaviour, I am investigating it and will update you definitily once I got the root cause.

    Thanks again !

  17. One of the unanticipated effects of Mark Miller&#39;s recent (and much appreciated) plugging of SharePoint

  18. Tasneem Nomani says:

    I want to submit the form annonymously. i:e have no value in the "created by" field.

    Is that possible?

  19. sowmyancs says:

    If you run your site in anonymous access, then the site will be running with the account IUSR_Machinename as the current user. So, it can’t identify who is actually submitting the form and thus we can’t update that field.

  20. Dan says:

    Ok, I’ve scoured the web for an easy way to do this without writing any code.  Here’s my solution:

    1) Open the file (make a copy beforehand):

    C:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATEGLOBALXMLONET.XML

    2) Browse to the part where it says <BaseType Title="Generic List" (in my case, I needed to change the "created by" and "modified by" attributes of a list)

    3) Scroll down a few lines to where it says FieldID and then "ColName="tp_Author" (created by) and also the linke "ColName="tp_Editor" (modified by)

    4) Remove ReadOnly="TRUE" from the line

    5) recycle the sharepoint IIS website and application pool

    6) Now open your list in a datasheet list view where you’ve added the 2 columns "modified by" and "created by".

    These fields should now be editable with simple cut/paste, etc..

    Hope this helps out some other frustrated sharepoint admins who are not trained developers!

    PS – don’t forget to reset the attributes back to read only when you’re done with the modifications…

  21. AVI says:

    Refer following blog to programmatically modify "Created By" and "Modified By" field values in SharePoint list:

    http://etechplanet.com/post/2008/12/06/How-to-change-the-values-of-Created-By-and-Modified-By-fields-in-SharePoint-list.aspx

  22. SPOLLACK says:

    Have you ever ran into when the Modified will switch to non RO, but the Created stays RO? I am using the Absense template from MS, and I cannot get the created to go NON RO, we would like to be able to change the field if we are putting in vacation for someone other that yourself.

  23. sowmyancs says:

    to be frank I didn’t get what is meant by "RO"/ "non RO" :), could you please help me to understand what is it?

  24. linusanjelo says:

    have you found a workaround on how to get the "created by" field in document libraries updated/edited?

    is the remove read-only on created by applicable to both lists and document libraries? and what do you mean when you said

    5) recycle the sharepoint IIS website and application pool

  25. JoeS says:

    linusangelo: If you don’t understand that, I strongly advise against you even trying this workaround.

  26. Bob says:

    Nice,

    So you start your article saying "Of course you can" to end with a little comment "Well.. actually it doesn’t work with document libraries"

    Good!

  27. sowmyancs says:

    Thanks for your suggestion Bob :), well, actually it does work through a work around as I have mentioned, though it will not work with the sample code that I have posted here.

    I have modfied the last paragraph. Thanks for your suggestions.

    Thanks,

    Sowmyan

  28. Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008

  29. vikash says:

    Hi Sowmyan,

    the code looks fine, but if a user doesnt have Edit access then you have to elevate the user permission , at that time code runs under system account , thou you keep current user id outside of the scope , but when the code reach to the oListItem.Update() then the final update will be done under system account , so the Author filed may be given user but modified by will be by system account . please let me know if i am wrong,

    Thanks & Regards,

    Vikash Shamra

  30. Darrin says:

    If you’re like me and don’t have access to the servers to use the API or change the XML files directly then just use the Lists.asmx web service. No IIS reset required! Of course you have to be familiar with writing web service calls.

    1. Get the List XML definition for all columns (GetList).

    2. Pull out the Author and Editor XML for the columns.

    3. Change ReadOnly="TRUE" to ReadOnly="FALSE" on both.

    4. Submit the web service request method UpdateList with the your XML in the update fields parameter.

    5. Edit your list in DataSheet view with the Modified By and Created By columns on there. Or you can use the web service again (UpdateListItems).

    6. Do step 3 and 4 to change it back to ReadOnly="TRUE"

    Check out the Lists.asmx MSDN reference to get your calls right.

  31. Mark says:

    In our discussion board the ‘Modified By’ column takes the name of the person who last changed the subject not contributed to the discussion.

    Is there a way to have the ‘Modified By’ field take the name of the last user to edit/contribute to the discussion thread?

    Thanks,

  32. sowmyan says:

    have you tried to attach an event handler try to modify the column by disabling and enabling the event in the code ?

  33. Clark says:

    You can also edit the created by value using a custom form and a Sharepoint:FormField pointed to Author.

    Only people with full control of the list will be able to edit though, for some reason.

  34. Yogesh says:

    Hi Sowmyan, can the discussion board's createdby & modifiedby fields be replaced with "Anonymous" through coding ? If so, please help with sample code.

  35. Sambo says:

    I saw the code but how can I apply that code to the sharepoint site or page?

  36. Westley says:

    You can actually update the author on a document library, but you must update the Author and the Editor fields, and call UpdateOverwriteVersion() on the item.

    You will most likely want to modifiy the vti_author property too. Assuming $itm is a valid item reference here is some powershell to accomplish the modification-

    $itm["Author"].tostring() #show current author

    $itm["Author"] = $oUser #list item author

    $itm.Properties["vti_author"] = $oUser.User.LoginName #file properties author

    $itm["Editor"] = $oUser #this needs to be changed as well to update the item.

    $itm.UpdateOverwriteVersion()

    $itm["Author"].tostring() #print the changed author

  37. Soniya Porwal says:

    Thanks sowmyancs ,great job u really make my work easier 🙂

  38. Prity says:

    Hi,

    I'v problem following trouble with my SharePoint, I a site owner I can see the contents of the fields: Createdby and modify by but the user of my site cann't see the contents of thies both fields, do you have any idea?

    Thanks in advance

    Prity

  39. Jacques says:

    Hi All

    I have a user that was lock on to SharePoint as a deferent user for a week and we locked him on as himself, but now when he modifies a document or does something in SharePoint 2010 it shows  that it was modified by the user he was locked in as.  Can anyone help me with this?    

  40. Swapnil Wani says:

    Hi,

    Can we update sharepoint list 'Created By' column value using javascript or any other option that will work on O365.?

    Please suggest.

    Regards.

    Swapnil Wani