In this blog, we will see the steps to get the list of the 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);
-
- }