How to change the value of “Created By” field in MOSS

SPSite site = new SPSite(siteUrl);

SPWeb web = site.OpenWeb();

web.AllowUnsafeUpdates = true;

SPList list = web.Lists["Test"];

SPListItemCollection collection = list.Items;

foreach (SPListItem item in collection )

{

SPUser user = web.EnsureUser("UserName");

string value1 = user.ID + ";#" + user.Name;

item["Author"] = value1; //for Created By field

item["Editor"]=value1 ;  //Modified By field

item.Update();  //Update the item

}

list.Update();

web.Update();


Its not necessary that same user should be logged in.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s