How to programmatically change a user field restricted to a single Sharepoint group in CSOM
-
26-01-2021 - |
문제
It possible in CSOM to change a user field to restrict the People picker to a single Sharepoint Group?
해결책
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();
}
제휴하지 않습니다 sharepoint.stackexchange