/******** 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();
         }
Advertisements