Welcome to MSDN Blogs Sign in | Join | Help

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

 

Published Friday, March 14, 2008 10:33 PM by sowmyancs

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# How to modify the custom People/Groups type column of a SharePoint List using Lists.ASMX

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

Friday, March 14, 2008 6:09 PM by welcome to the world of my sharepoint customization

# Updating the “Created By” and “Modified By” Columns in SharePoint lists

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

Thursday, May 22, 2008 11:41 AM by SharePoint Thinks, Links and Clinks

# SharePoint Kaffeetasse #70

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

Wednesday, May 28, 2008 4:16 AM by Mirrored Blogs

# SPPD099 SharePointPodcast

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

Friday, June 06, 2008 11:09 AM by SharePoint, SharePoint and stuff

# SPPD099 SharePointPodcast

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

Friday, June 06, 2008 11:10 AM by SharePointPodcast.de

# SPPD099 SharePointPodcast

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

Friday, June 06, 2008 11:47 AM by Mirrored Blogs

#

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

Friday, June 20, 2008 8:28 PM by Sowmyan's SharePoint Developer Blog

# How to show task creator & modifier name instead of "System Account" in the Task Library

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

Friday, June 20, 2008 8:29 PM by Sowmyan's SharePoint Developer Blog

# SPPD100 SharePointPodcast

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

Wednesday, June 25, 2008 11:01 AM by SharePointPodcast.de

# SPPD100 SharePointPodcast

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

Wednesday, June 25, 2008 11:02 AM by Michael Greth MVP SharePoint Blog

# SPPD100 SharePointPodcast

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

Wednesday, June 25, 2008 11:50 AM by Mirrored Blogs

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

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

Sunday, September 21, 2008 1:22 PM by Dag

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

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.

Monday, September 22, 2008 7:52 PM by sowmyancs

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

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.

Wednesday, November 12, 2008 3:54 PM by arosoccer

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

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.

Wednesday, November 12, 2008 4:18 PM by arosoccer

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

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 !

Wednesday, November 12, 2008 10:47 PM by sowmyancs

# Editing Columns in a SharePoint Document Library Redux

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

Thursday, November 13, 2008 5:01 PM by SharePoint Blank

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

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

Is that possible?

Wednesday, December 03, 2008 1:27 PM by Tasneem Nomani

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

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.

Thursday, December 04, 2008 12:25 AM by sowmyancs

# Remove Read-Only on "Created By", etc.

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 Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\XML\ONET.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...

Wednesday, December 10, 2008 6:45 AM by Dan

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

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

Tuesday, December 30, 2008 9:17 AM by AVI

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

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.

Monday, January 12, 2009 5:34 PM by SPOLLACK

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

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

Saturday, February 21, 2009 12:28 AM by sowmyancs

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

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

Thursday, March 12, 2009 10:03 AM by linusanjelo

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

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

Friday, March 13, 2009 10:09 AM by JoeS

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

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!

Monday, May 18, 2009 6:28 PM by Bob

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

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

Monday, May 18, 2009 7:00 PM by sowmyancs

# SPPD099 SharePointPodcast

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

Tuesday, June 09, 2009 7:29 AM by SharePointPodcast

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

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

Thursday, August 27, 2009 9:26 AM by vikash

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

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.

Thursday, September 03, 2009 12:08 PM by Darrin

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

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,

Wednesday, September 09, 2009 11:20 PM by Mark

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

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

Thursday, September 17, 2009 9:33 PM by sowmyan

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker