In this blog, we will see the steps to get the list of the users with specific roles in SharePoint Online, using CSOM.

  1. using (var context = new ClientContext(siteurl))
  2. {
  3. context.Credentials = new SharePointOnlineCredentials(userEmailAddress, password);
  4. context.Load(context.Web, w => w.Title);
  5. context.ExecuteQuery();
  6. var users = context.LoadQuery(context.Web.SiteUsers);
  7. context.ExecuteQuery();
  8. foreach(var user in users)
  9. {
  10. Console.WriteLine(user.Name);
  11. Console.WriteLine(user.Email);
  12. }