Question

I have a SPUser and I want to get all the user groups in which the SPUser exists. How can i get all the SPGroups containing the SPUser programatically?. Sample codes and useful links would be very helpful. Thanks.

Was it helpful?

Solution

Do something like this..(I have not tested..pls debug and test)

List<string> lstgroup=new List<string>();

 SPGroupCollection groupCollection = web.Groups;
        foreach (SPGroup grp in groupCollection)
        {
            if (grp.ContainsCurrentUser)
            {
                lstgroup.add(grp);
            }
        }

OTHER TIPS

SPUser.Groups returns a collection of SPGroups which the user is a member. Here is the documentation link

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top