The following example returns all the users from the given SharePoint Site Group using SharePoint 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 GetGroupUsers
- {
- 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();
- RETRY_GROUP:
- Console.Write("Enter Group Name: ");
- string groupName = Console.ReadLine();
- Console.WriteLine();
- try
- {
- ClientContext ctx = new ClientContext(strURL);
- ctx.Credentials = new NetworkCredential(strUserName, pass);
- Web web = ctx.Web;
- Group group = web.SiteGroups.GetByName(groupName);
- //Parameters to receive response from the server
- ctx.Load(web, w => w.Title);
- ctx.Load(group, grp => grp.Title, grp => grp.Users, grp => grp.Owner);
- ctx.ExecuteQuery();
- Console.WriteLine("Groups Name: " + group.Title);
- Console.WriteLine("Users Count: " + group.Users.Count);
- Console.WriteLine("Group Owner: " + group.Owner.Title);
- Console.WriteLine("Users:");
- foreach(User usr in group.Users)
- {
- Console.WriteLine(usr.Title);
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error: " + ex.Message);
- Console.Write("Do you want to continue (y / n):");
- ConsoleKeyInfo boolContinue = Console.ReadKey();
- Console.WriteLine();
- if (boolContinue.KeyChar == 'y')
- goto RETRY_GROUP;
- else
- Console.Write("Enter to Exit.");
- }
- 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;
- }
- }
- }
Supported Versions:
SharePoint 2013 + SharePoint Online

Neha NayyarPosted Sep 18, 2018, 7:33 AM
Thanks for the post, but I am getting 403 forbidden error, what can I do to correct ? Does it require tenant admin access ? :)
Santhakumar MunuswamyPosted Sep 26, 2015, 12:39 PM
Nice share