Get All Users From Site Group in SharePoint using CSOM

The example in this topic show how to use CSOM to Get All Users From Site Group in SharePoint

  • using Microsoft.SharePoint.Client;
  • using System.Linq;
  •  
  • using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
  • {
  • // Get group object using group name
  • Group oGroup = clientcontext.Web.SiteGroups.GetByName("Group Name");
  •  
  • // Get collection of users in the above group
  • UserCollection oUserCollection = oGroup.Users;
  •  
  • // Load the user collection object
  • clientcontext.Load(oUserCollection);
  •  
  • clientcontext.ExecuteQuery();
  •  
  • // Iterate through each User
  • foreach (User oUser in oUserCollection)
  • {
  • Console.WriteLine("User Name: " + oUser.Title);
  • }
  • }

Thank you for reading this article. This code was tested in SharePoint 2013


© 2019 Code SharePoint