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.
2 Answers
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);
}
}
SPUser.Groups
returns a collection of SPGroups which the user is a member. Here is the documentation link