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