Instead of user enumeration and check roles for each user, you can get role assignments for web and get all users for corresponding role.
Like this:
using(SPWeb web = SPSite(webUrl).OpenWeb())
{
SPRoleDefinitionCollection roleDefinitions = web.RoleDefinitions;
SPRoleDefinition roleDefinition = roleDefinitions["Full Control"];
foreach (SPRoleAssignment roleAssigment in web.RoleAssignments)
{
if (roleAssigment.RoleDefinitionBindings.Contains(roleDefinition))
{
SPPrincipal oPrincipal = roleAssigment.Member;//it can be SPUser or SPGroup, you can process and add it to the result
}
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.