Update the value of User/UserMulti column in SharePoint using Client Object Model
ClientContext ctx = new ClientContext(weburl);
ctx.Credentials = new SharePointOnlineCredentials(userName, passWord);
List list = ctx.Web.Lists.GetByTitle("ListTitle");
ListItem currentItem = list.GetItemById(1);
FieldUserValue[] userValueCollection = new FieldUserValue[1];
//Get all the users of this Web
UserCollection userCollection = this.ctx.Web.SiteUsers;
this.ctx.Load(userCollection, w => w.Include(p => p.Id, p => p.Title));
this.ctx.ExecuteQuery(this.ctx);
User user = userCollection.FirstOrDefault(p => p.Title.ToLower().Trim() == userTitle.ToLower().Trim());
//Making sure that a user of title userTitle is present in this Web
if (user != null)
{
FieldUserValue fieldUserVal = new FieldUserValue();
fieldUserVal.LookupId = user.Id;
userValueCollection.SetValue(fieldUserVal, 0);
}
currentItem["MultiUserValCol"] = userValueCollection;
currentItem.Update();
this.ctx.ExecuteQuery();
As you can see that updating a multiUser column is along the same line as updating a LookupMulti column. Hence, there are a couple of things that one should take care of while updating this column. Those are mentioned in my previous blog where I have discussed about updating a LookupMulti column. here. https://realmpksharepoint.wordpress.com/2014/01/19/update-a-lookupmulti-column-value-in-sharepoint-using-client-object-model-c/
I just wanna say thank you for sharing the content and wish you all the best for your website and your whole team.
Count
http://www.imarksweb.org
LikeLike
Useful article, helped me save a lot of time in my Sharepoint developments, thanks
LikeLike