Posted by: msqr | November 1, 2010

Sharepoint tips – Update Created By/Modified by user with logged in user

Normally, we run code under elevated previleges that takes System User account in created by modified by. If we want to reflect Created By/Modifed by with logged in user, you have to specify UserToken while opening site.

SPUserToken loggedInUserToken = SPContext.Current.Web.CurrentUser.UserToken;

using (SPSite objSite = new SPSite(SPContext.Current.Web.Url,loggedInUserToken))
using (SPWeb objWeb = objSite.OpenWeb())
objWeb.AllowUnsafeUpdates = true;
SPListItem lstItem= listItemCollection.Add();
lstItem[“Foo”] = “Bar”


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s


%d bloggers like this: