Skip to content

How to update the “Author / Created by” and “Editor / Modified By” fields

May 24, 2011

Sometimes is useful to overwrite the author and/or the editor fields, specially if you are using SPSecurity.RunWithElevatedPrivileges and you don’t want the item to be saved as “System Account”.

For SPListItem

//Add a new item
SPListItem objSPListItem = objSPList.Items.Add();

objSPListItem["Editor"] = SPContext.Current.Web.CurrentUser;
objSPListItem["Author"] = SPContext.Current.Web.CurrentUser;
//Update item values
objSPListItem.Update();

For SPFile

// Upload document
SPFile spfile = myLibrary.Files.Add(FileUpload1.PostedFile.FileName, FileUpload1.PostedFile.InputStream, replaceExistingFiles);

// Commit
myLibrary.Update();

spfile.Item["Editor"] = SPContext.Current.Web.CurrentUser;
spfile.Item["Author"] = SPContext.Current.Web.CurrentUser;

//Update item values
spfile.Item.Update();
Advertisements

From → SharePoint 2010

Leave a Comment

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

%d bloggers like this: