In this blog, we will see the list of steps to get the list of users with the specific roles in SharePoint Online, using CSOM. A SharePoint group is a collection of users, who all have the same set of permissions for the sites and its content. In SharePoint Online, there is always a specific task for the list of users, who belong to the certain roles and titles. Create a clientcontext object and then access SharePoint Online, using your Office 365 E-mail address and password, retrieve the set of site users, using Web object. The code snippet is given below to achieve the same.

  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. }