6

I have been trying to find how to find what permission level a group (within SPWeb.Groups) has. But it seems like there is no easy way to do this. Any ideas?

I have tried creating SPRoleAssignment and passing the group to get the RoleDefinitionBindings, but it seems like creating a new instance does not help with finding existing permission level.

Using SPWeb.AssociatedOwnerGroup does not give me all the "full permission" groups either.

Any help will be greatly appreciated. Thank you!

1 Answer 1

8

Prints out all the groups for the SPWeb and the group's role names:

using (SPSite site = new SPSite("http://server/sites/sitecollection/"))
{
    using (SPWeb web = site.OpenWeb("test"))
    {
        foreach (SPRoleAssignment roleAssignment in web.RoleAssignments)
        {
            if (roleAssignment.Member is SPGroup)
            {
                Console.WriteLine("Group: " + roleAssignment.Member.Name);
                foreach (SPRoleDefinition roleDefinition in roleAssignment.RoleDefinitionBindings)
                {
                    Console.WriteLine("\t" + roleDefinition.Name);
                }
            }
        }
    }
}
}
4
  • Thank you!! I was creating the SPRoleAssignment and passing the group to it for instantiation - silly me :) Thanks a bunch!
    – Tom
    Commented Apr 17, 2012 at 19:36
  • this throws an exception if my user permission level is low can any one tell me how solve this.
    – user8284
    Commented May 10, 2012 at 9:33
  • @thomas Not sure what you're trying to do... you need permission to view the groups?
    – Kit Menke
    Commented May 10, 2012 at 19:02
  • I know this is an old post - he might've solved his problem already, but for anyone finding they need higher privileges to let the code run, just put SPSecurity.RunWithElevatedPrivileges(delegate() { .... } around any block you find that needs elevated privileges.
    – vapcguy
    Commented May 1, 2015 at 1:33

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.