How to Create a New Site Group Programmatically

Steps
  • Open Visual Studio in your system
  • Select Console Applciation template and give as name .
  • Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
  • Replace Program.cs with the source code  
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using System.Threading.Tasks;  
  6. using Microsoft.SharePoint.Client;  
  7. using System.IO;  
  8.   
  9. namespace CSOMCodeSamples  
  10. {  
  11.    class Program  
  12.    {  
  13.       static void Main(string[] args)  
  14.       {  
  15.   
  16.          // ClientContext - Get the context for the SharePoint Site  
  17.   
  18.          ClientContext clientContext = new ClientContext("http://gauti.sharepoint.com/sites/CSOM/");  
  19.          // Get the SharePoint web  
  20.          Web web = clientContext.Web;  
  21.   
  22.          // Get all the site groups  
  23.          GroupCollection groupColl = web.SiteGroups;  
  24.   
  25.          // Create a new site group  
  26.          GroupCreationInformation creationInfo = new GroupCreationInformation();  
  27.          creationInfo.Title = "gautiGroup";  
  28.          creationInfo.Description = "Custom group created using CSOM";  
  29.          Group newGroup = groupColl.Add(creationInfo);  
  30.          clientContext.Load(newGroup);  
  31.          // Execute the query to the server  
  32.          clientContext.ExecuteQuery();  
  33.          // Display the newly created group name  
  34.          Console.WriteLine(newGroup.Title + " is created successfully");  
  35.          Console.ReadLine();  
  36.       }  
  37.    }  
  38. }  
Hit f5 and check the out put in SharePoint group created successfully.