I want to get all group that current user is member in SharePoint server 2010 using Client Object Model C#. Anyone help me.

  • There is another post asking same question with useful answers. – Mark L Oct 18 '16 at 1:18
  • 1
    @Mark, The above post is using JSOM and thien thai is asking with Client Object model with C#. So is it useful? – Ram Oct 18 '16 at 5:20
  • Please check my Updated answer – Akshay Dattatray Nangare Oct 18 '16 at 7:03
using( ClientContext clientContext = new 

  #Get Group Collection           
  GroupCollection collGroup = clientContext.Web.SiteGroups;


  groups => groups.Include(
  group => group.Users));


  #iterate through group            
  foreach (Group oGroup in collGroup)
     UserCollection collUser = oGroup.Users;

     foreach (User oUser in collUser)
         #check if user is exist or not


|improve this answer|||||
  • good to hear from you! – Akshay Dattatray Nangare Oct 18 '16 at 9:38
  • If my answer help you to find solution then, mark this answer as accepted. – Akshay Dattatray Nangare Oct 18 '16 at 9:55
  • i don't see any link or button to mark you answer. – thien thai Oct 18 '16 at 10:04
  • Find tick (Check mark) , at the left corner of my answer. If you not found then ignore – Akshay Dattatray Nangare Oct 18 '16 at 10:12
  • This is wrong... if there are thousands of groups with thousands of users, either of these 2 bad things will happen: 1. the query will throw "Using too many resources" exception on SP server or 2. it will run very long and the result will occupy a brutal amount of operating memory on the client app using csom.... – Michal Hainc Aug 7 '18 at 9:03

I am doing it in SharePoint 2016, maybe someone wanna know you can load only groups from current user.

using(ClientContext ctx = new ClientContext("http://MyServer/sites/MySiteCollection"))
    var userGroups = ctx.Web.CurrentUser.Groups;

    return userGroups.Select(a => a.Title).ToList();

Hope this helps.

|improve this answer|||||

If you need to get the Groups of a specific user, you could do something like:

using(SPSite site = new SPSite("http://yoursite"))
    using(SPWeb web = site.openWeb())
        SPUser user = web.CurrentUser;
        SPGroupCollection groups = user.Groups;
        foreach(SPGroup group in groups)
            // Get the necessary info, for example:
            // string groupName = group.Name;
|improve this answer|||||
  • You need to use ClientContext insted of SPSite – Akshay Dattatray Nangare Oct 18 '16 at 8:44
  • Sorry, I misread the question. Downvote accepted. – AWJ Oct 18 '16 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.