Monday, March 22, 2010

Get all users with Full Control for the web

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

}

}

}

MSDN forum

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.