Question

I have the following CSOM code:

Group group = web.SiteGroups.GetByName(subsitename);                     
List<FieldUserValue> currentgroupUsers = new List<FieldUserValue>();
foreach (User user2 in group.Users)
{
     currentgroupUsers.Add(***********);
}

So how I can convert/cast a User object to FieldUserValue object?

Was it helpful?

Solution

Try something like below:

List<FieldUserValue> currentgroupUsers = new List<FieldUserValue>();

foreach (User user2 in group.Users)
{
    var userLookupValue = new FieldLookupValue { LookupId = user2.Id };
    currentgroupUsers.Add(userLookupValue);
}

oListItem["PersonOrGroupField"] = currentgroupUsers.ToArray();
oListItem.Update();
context.ExecuteQuery();
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top