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