The following example returns all the Groups available in Site using SharePoint's Managed Client Side Object Model.
After creating a console application project in Visual Studio solution, add the following assembly references to the project.
Microsoft.SharePoint.Client
Microsoft.SharePoint.Client.Runtime
- using Microsoft.SharePoint.Client;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- namespace GetSiteGroups
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Get Site Url fro user
- Console.Write("Enter Site URL: ");
- string strURL = Console.ReadLine();
- //Get Username from user in the format of (Domain/Login ID)
- Console.Write("Enter UserName (domain/userid): ");
- string strUserName = Console.ReadLine();
- Console.Write("Enter your password: ");
- string pass = getPassword();
- Console.WriteLine();
- ClientContext ctx = new ClientContext(strURL);
- ctx.Credentials = new NetworkCredential(strUserName, pass);
- Web web = ctx.Web;
- //Parameters to receive response from the server
- //SiteGroups property should be passed in Load method to get the collection of groups
- ctx.Load(web, w => w.Title, w => w.SiteGroups);
- ctx.ExecuteQuery();
- GroupCollection groups = web.SiteGroups;
- Console.WriteLine("Groups associated to the site: " + web.Title);
- Console.WriteLine("Groups Count: " + groups.Count.ToString());
- foreach(Group grp in groups)
- {
- Console.WriteLine(grp.Title);
- }
- Console.Read();
- }
- private static string getPassword()
- {
- ConsoleKeyInfo key;
- string pass = "";
- do
- {
- key = Console.ReadKey(true);
- // Backspace Should Not Work
- if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
- {
- pass += key.KeyChar;
- Console.Write("*");
- }
- else
- {
- if (key.Key == ConsoleKey.Backspace && pass.Length > 0)
- {
- pass = pass.Substring(0, (pass.Length - 1));
- Console.Write("\b \b");
- }
- }
- }
- // Stops Receving Keys Once Enter is Pressed
- while (key.Key != ConsoleKey.Enter);
- return pass;
- }
- }
- }

Rohith reddyPosted Sep 20, 2019, 4:10 AM
It returns all the groups including system groups i.e. Limited Access System Group and SharingLinks.[GUID].OrganizationView.[GUID]. I don't need these groups. Is there any way to get only Groups which are showing in https://servername/site/_layouts/15/groups.aspx. except Security Groups.
Santhakumar MunuswamyPosted Sep 26, 2015, 12:40 PM
Nice share