xxxxxxxxxx
/// 08/11/2022 Mahesh Kumar Yadav. <br/>
/// <summary>
/// Create group in site level
/// </summary>
using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
{
// NOTE: The user who is running the code will be added as "Group Ownr"
GroupCollection oGroupCollection = clientcontext.Web.SiteGroups;
// GroupCreationInformation object
GroupCreationInformation oGroupCreationInformation = new GroupCreationInformation();
oGroupCreationInformation.Title = "New Group";
oGroupCreationInformation.Description = "Group description";
Group oGroup = oGroupCollection.Add(oGroupCreationInformation);
clientcontext.ExecuteQuery();
}
xxxxxxxxxx
using Microsoft.SharePoint.Client;
using System.Linq;
/// 08/11/2022 Mahesh Kumar Yadav. <br/>
/// <summary>
/// Get all the groups
/// </summary>
using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
{
// Get all the groups at site level
GroupCollection oGroupCollection = clientcontext.Web.SiteGroups;
clientcontext.Load(oGroupCollection);
clientcontext.ExecuteQuery();
// Iterate through each group
foreach (Group oGroup in oGroupCollection)
{
// Print group title
Console.WriteLine(oGroup.Title);
}
}