I want to get a user and all his groups by a login name. Easy to do in Sharepoint 2013.

        clientContext.Load(site, l => l.RootWeb.SiteUsers, l => l.RootWeb.Id, l => l.Id);

        var user = site.RootWeb.SiteUsers.GetByLoginName(loginName);
        clientContext.Load(user, l => l.Groups, l => l.Id, l => l.LoginName);

As both the SiteUsers as well as the Groups Property don't exist in SP2010 i have no idea how to accomplish this. Any ideas who i can get the needed information?

The only information i can use is the login name, CurrentUser or something similar won't work.

EDIT: I have found a way to get the User object via CurrentUser, nevertheless i can't find a reliable way to get the groups for this user. I can iterate through all groups of the site and check if they contain the user. But then i have to also resolve all AD Groups and consider special AD Groups like "NT AUTHORITY\authenticated users". Makes the whole process rater slow. Is there a faster way to do this in SP2010?

1 Answer 1


You could consider the following approach to retrieve user groups using SharePoint 2010 CSOM:


var user = site.RootWeb.CurrentUser;
var siteGroups = site.RootWeb.SiteGroups; 
ctx.Load(siteGroups, gcol => gcol.Include(g => g.LoginName,g => g.Users));
var userGroups = siteGroups.ToList().Where(g => g.Users.ToList().Exists(u => u.Id == user.Id)); //filter groups     
  • here variable userGroups will return all properties of that groups?? Because I tried this code 2 days back, and I was not able to iterate through that collection and get any details of groups... Finally I followed different approach
    – Gaurravs
    Dec 12, 2015 at 18:17
  • Its loading all groups from site with all users... with big sharepoints with many groups and users per site this will be a problematic performance hungry query, in fact it could get throttled by the server
    – michalh
    Aug 7, 2018 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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