Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Monday, April 23, 2012

How to pass Current Logged User value into SharePoint Created By Column while insertion into SharePoint List.


SPSecurity.RunWithElevatedPrivileges(delegate()
            {
            SPWeb currentWeb = SPContext.Current.Web;   
            SPList lst = currentWeb.Lists["Sample"];
                SPListItemCollection myColl = lst.Items;
                SPListItem item = myColl.Add();
                item["Title"] = txtTitle.Text;   
                SPFieldUserValue value = new SPFieldUserValue(currentWeb, currentWeb.CurrentUser.ID, currentWeb.CurrentUser.LoginName);
                item["Author"] = value.LookupId;
                item.Update();

            });

No comments:

Post a Comment