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

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

# 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

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

# 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

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

# SharePoint Kaffeetasse #70

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

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

# SPPD099 SharePointPodcast

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

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

#

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

# 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

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

# SPPD100 SharePointPodcast

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

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

# 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

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

# 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.

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

# 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 4:18 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 10:47 PM by sowmyancs

# 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 !

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

# 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

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 ?

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

Is that possible?

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

# 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.

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

# 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...

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

# 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

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

# 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.

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

# 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?

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

# 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

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

# 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.

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

# 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 7:00 PM by sowmyancs

# 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

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

# SPPD099 SharePointPodcast

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

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker