tag:blogger.com,1999:blog-6241523649263677429.post3871659044590144142..comments2023-04-09T04:51:01.351-04:00Comments on Disha Shah's Blog: How to add/update SharePoint person/group field from Object modelDisha shahhttp://www.blogger.com/profile/02518044206110358922noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-6241523649263677429.post-67868726069078537172010-01-27T10:21:25.000-05:002010-01-27T10:21:25.000-05:00How do you add multiple people to the field? Is t...How do you add multiple people to the field? Is there a separator that needs to be used?NeedToKnownoreply@blogger.comtag:blogger.com,1999:blog-6241523649263677429.post-24641787182282293782010-01-27T13:31:09.000-05:002010-01-27T13:31:09.000-05:00HiSPUser object, it gives the ID (SPUser.ID.ToStri...Hi<br><br>SPUser object, it gives the ID (SPUser.ID.ToString() and SPUser.LoginName.ToString() ) and then use simple string building to get the string in the right format for the ‘Person or Group’ field.<br><br>Please review the following code in which it accepts a semi-colon delimited list of aliases (i.e. domain\user;domain\user;domain\user) and then adds them to a ‘Person or Group’ field called ‘MyPersonField’ in a list. <br><br><br>string sAliases = "domain\user;domain\user;domain\user";<br><br>string UserNames = "";<br><br>using (SPSite site = new SPSite("URLof the site")) <br>{ <br> site.AllowUnsafeUpdates = true; <br> using (SPWeb web = site.RootWeb) <br> { <br> web.AllowUnsafeUpdates = true; <br> string[] aAliases = sAliases.Split(';'); <br> foreach (string sAlias in aAliases) <br> { <br> SPUser user = web.EnsureUser(sAlias); <br> UserNames += user.ID.ToString() + ";#" + user.LoginName.ToString() + ";#"; <br> } <br> web.Update(); <br> } <br>} <br><br>if (UserNames.EndsWith(";#")) <br>{ <br> UserNames = UserNames.Substring(0, UserNames.Length - 2); <br>}<br><br><br>SPList l = web.Lists[""]; <br>SPListItem li= l.Items.Add(); <br>li["Title"] = UserNames ; <br>li["MyPerson"] = UserNames ; <br>li.Update(); <br><br><br>Hope this Helps!!!<br>Disha Shahdishashah08noreply@blogger.com