Set Site Group Owner in SharePoint using CSOM

The example in this topic show how to use CSOM to Set Site Group Owner in SharePoint

  • using Microsoft.SharePoint.Client;
  • using System.Linq;
  •  
  • using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
  • {
  • // Option 1: Set a User as an owner
  • // Get the user object. Enter the "Logon Name" of the user you want to add as Group Owner
  • User oUser = clientcontext.Web.EnsureUser("Logon Name");
  •  
  • // Option 2: Set Group as an owner
  • Group ownerGroup = clientcontext.Web.SiteGroups.GetByName("test Visitors");
  •  
  • // Specify the group name over here. This is the group of which "owner" needs to set
  • Group oGroup = clientcontext.Web.SiteGroups.GetByName("New Group");
  •  
  • // Set the owner property of the group
  • // You can either specify "User" from Option 1 or "Group" from Option 2
  • oGroup.Owner = oUser;
  •  
  • oGroup.Update();
  • clientcontext.ExecuteQuery();
  • }

Thank you for reading this article. This code was tested in SharePoint 2013


© 2019 Code SharePoint