Update people field

The following code sample add a new member to the SharePoint 2013 Community Site Member list.  It update the "Member" field.


using (SPSite site = new SPSite("http://siteurl/"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPList members = web.Lists.TryGetList("Community Members");

                        SPListItem newMember = members.AddItem();
                     
                        SPUser ensuredUser2 = web.EnsureUser("domain\\loginName");
                        SPFieldUserValue userValue = new SPFieldUserValue(web, ensuredUser2.ID, ensuredUser2.LoginName);
                        newMember["Member"] = userValue;
                        newMember.Update();

                    }
                }

Comments

Popular posts from this blog

SharePoint 2013 App Details Page Error

SharePoint 2013 - Working with Display Template for Content Search Web Part

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365