Update a UserMulti Column value in Client Object Model C#

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/

2 thoughts on “Update a UserMulti Column value in Client Object Model C#

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.