How to modify the values of "Created By", "Modified By" columns in SharePoint lists
SPSite oSite = new SPSite("http://portal");
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.Lists["mylist"];
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, "Ashish Kanoongo");
oListItem["Author"] = oUser;//created by - "14;#Ashish Kanoongo"
oListItem["Editor"] = oUser;//modified by - "14;#Ashish Kanoongo"
oListItem.Update();
}
oWeb.Update();
0 comments:
Post a Comment