次の方法で共有


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("https://<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("https://<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 : https://blogs.msdn.com/tadd/archive/2008/05/22/updating-the-created-by-and-modified-by-columns-in-sharepoint-lists.aspx

Comments

  • Anonymous
    March 14, 2008
    The comment has been removed

  • Anonymous
    May 22, 2008
    Thinks Ever had the good old System Account show up as your author or editor, oops I mean &#8220;Created

  • Anonymous
    May 27, 2008
    Entwicklung What you need to know about AllowUnsafeUpdates (Part 1) What you need to know about AllowUnsafeUpdates

  • Anonymous
    June 06, 2008
    Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008)

  • Anonymous
    June 06, 2008
    Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008)

  • Anonymous
    June 06, 2008
    Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008

  • Anonymous
    June 20, 2008
    Whenever we create a SharePoint site we will get a default list called &#8220;Tasks&#8221;. This is one

  • Anonymous
    June 20, 2008
    Whenever we create a SharePoint site we will get a default list called &#8220;Tasks&#8221;. This is one

  • Anonymous
    June 25, 2008
    Direkter Download: SPPD-100-2008-06-25 Behind the Scene - QIK Video Aktuell SharePointCommunityCamp September

  • Anonymous
    June 25, 2008
    Direkter Download: SPPD-100-2008-06-25 Behind the Scene - QIK Video Aktuell SharePointCommunityCamp September

  • Anonymous
    June 25, 2008
    Direkter Download: SPPD-100-2008-06-25 Behind the Scene - QIK Video Aktuell SharePointCommunityCamp September

  • Anonymous
    September 21, 2008
    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

  • Anonymous
    September 22, 2008
    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.

  • Anonymous
    November 12, 2008
    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.

  • Anonymous
    November 12, 2008
    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.

  • Anonymous
    November 12, 2008
    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 !

  • Anonymous
    November 13, 2008
    One of the unanticipated effects of Mark Miller&#39;s recent (and much appreciated) plugging of SharePoint

  • Anonymous
    December 03, 2008
    I want to submit the form annonymously. i:e have no value in the "created by" field. Is that possible?

  • Anonymous
    December 03, 2008
    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.

  • Anonymous
    December 09, 2008
    The comment has been removed

  • Anonymous
    December 30, 2008
    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

  • Anonymous
    January 12, 2009
    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.

  • Anonymous
    February 20, 2009
    to be frank I didn't get what is meant by "RO"/ "non RO" :), could you please help me to understand what is it?

  • Anonymous
    March 12, 2009
    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

  1. recycle the sharepoint IIS website and application pool
  • Anonymous
    March 13, 2009
    linusangelo: If you don't understand that, I strongly advise against you even trying this workaround.

  • Anonymous
    May 18, 2009
    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!

  • Anonymous
    May 18, 2009
    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

  • Anonymous
    June 08, 2009
    Direkter Download: SPPD-099-2008-06-06 Aktuell SharePointCommunityCamp September 2008 (15.9./16.9.2008

  • Anonymous
    August 27, 2009
    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

  • Anonymous
    September 03, 2009
    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.
  • Anonymous
    September 09, 2009
    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,

  • Anonymous
    September 17, 2009
    have you tried to attach an event handler try to modify the column by disabling and enabling the event in the code ?

  • Anonymous
    August 12, 2010
    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.

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

  • Anonymous
    March 13, 2012
    I saw the code but how can I apply that code to the sharepoint site or page?

  • Anonymous
    June 18, 2012
    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

  • Anonymous
    October 10, 2012
    Thanks sowmyancs ,great job u really make my work easier :)

  • Anonymous
    July 09, 2013
    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

  • Anonymous
    January 04, 2015
    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?    

  • Anonymous
    June 09, 2015
    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