How to programmatically change a user field restricted to a single Sharepoint group in CSOM
-
26-01-2021 - |
Pregunta
It possible in CSOM to change a user field to restrict the People picker to a single Sharepoint Group?
Solución
I've found this solution:
string weburl = "http://piero.it/sites/pdvc/TestCon2004";
string listName = "Agenda";
string fieldName = "Utente";
string groupName = "CreatoriRaccolte";
using (ClientContext clientContext = new ClientContext(weburl))
{
Group group = clientContext.Web.SiteGroups.GetByName(groupName);
clientContext.Load(group);
clientContext.ExecuteQuery();
List list = clientContext.Web.Lists.GetByTitle(listName);
clientContext.Load(list, l => l.Fields);
clientContext.ExecuteQuery();
Field field = list.Fields.GetByInternalNameOrTitle(fieldName);
FieldUser fieldUser = clientContext.CastTo<FieldUser>(field);
fieldUser.SelectionMode = FieldUserSelectionMode.PeopleOnly;
fieldUser.SelectionGroup = group.Id;
fieldUser.Update();
clientContext.Load(fieldUser);
clientContext.ExecuteQuery();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a sharepoint.stackexchange