How to add a SharePoint group as the owner of a group with a client object model?

If you want to create a group and add the default group owner and user, you can use the following codes:

string siteUrl = "https://server/sites/sitename"; ClientContext clientContext = new ClientContext(siteUrl); Web web = clientContext.Web; GroupCreationInformation groupCreationInfo = new GroupCreationInformation(); groupCreationInfo.Title = "Custom Group"; groupCreationInfo.Description = "description ..."; User owner = web.EnsureUser(@"domain\username1"); User member = web.EnsureUser(@"domain\username2"); Group group = web.SiteGroups.Add(groupCreationInfo); group.Owner = owner; group.Users.AddUser(member); group.Update(); clientContext.ExecuteQuery(); 

My question is: I know how to add a user as the owner of the group, but if I want to add the SharePoint Technical Support group as the owner of the group, what should be the code?

+5
source share
1 answer

Use the GroupCollection.GetByName or GroupCollection.GetById method to retrieve an existing group from the site, and then set the Group.Owner property to a value, for example:

 using (var ctx = new ClientContext(webUri)) { ctx.Credentials = credentials; var groupCreationInfo = new GroupCreationInformation { Title = groupName, Description = groupDesc }; var groupOwner = ctx.Web.SiteGroups.GetByName("Tech Support"); //get an existing group var group = ctx.Web.SiteGroups.Add(groupCreationInfo); group.Owner = groupOwner; group.Update(); ctx.ExecuteQuery(); } 
+6
source

Source: https://habr.com/ru/post/1201773/


All Articles