Home » General Scripting and Coding » SharePoint » Find a Users SharePoint Group Membership

Find a Users SharePoint Group Membership

Posted on by

This example shows how we can find a users SharePoint group membership by utilising SPGroupCollection.  Remember that if you are running your code with SPSecurity.RunWithElevatedPrivileges, you should set the SPUser value OUTSIDE of this elevated code otherwise it will not work for the current user running the browser session.

SPUser user = SPContext.Current.Web.CurrentUser;

SPGroupCollection groupColl = user.Groups;
foreach (SPGroup grp in groupColl)
    groupMembership.Text += grp.Name + ",";


Comments have now been disabled. If you have a question to ask about this post please ask the community!