How to get the list of users with specific roles in SharePoint online using CSOM?

Hello SharePointers,

In this blog, we can take a look at the CSOM code to  get the list of users with specific roles in SharePoint online using CSOM.

using (var context = new ClientContext(siteurl))
{
context.Credentials = new SharePointOnlineCredentials(userEmailAddress, password);
context.Load(context.Web, w => w.Title);
context.ExecuteQuery();
var users = context.LoadQuery(context.Web.SiteUsers);

context.ExecuteQuery();

foreach(var user in users)
{
Console.WriteLine(user.Name);

Console.WriteLine(user.Email);

}
Happy SharePointing Folks!!

Leave a Reply

Your email address will not be published. Required fields are marked *