JohnnyLiao
JohnnyLiao

Reputation: 463

How to check permissions for a user or group in Sharepoint 2010 using C#?

In Sharepoint 2010, clicking "Site Actions"--> "Site Permission" --> "Check Permissin", you can get permission by user. How can I do the same thing using sharepoint API in c#?

Upvotes: 1

Views: 9294

Answers (2)

Tiago
Tiago

Reputation: 2167

The method "GetUserEffectivePermissionInfo" server users only. If the permissions need to find a group, just do this:

using (SPSite site = new SPSite("/"))
{
    using (SPWeb web = site.OpenWeb())
    {
        SPGroup spGroupItem = web.Groups["GroupName"];
        SPRoleAssignment oRoleAssignment = web.RoleAssignments.GetAssignmentByPrincipal(spGroupItem);

        foreach (SPRoleDefinition inRole in oRoleAssignment.RoleDefinitionBindings)
        {
            //inRole.id //inRole.Name
            //1073741829 //limited access
        }
    }
}

Upvotes: 3

Rich Bennema
Rich Bennema

Reputation: 10335

Try SPWeb.GetUserEffectivePermissionInfo

Gets the effective permissions that the specified user has and the role assignments related to this user within this scope.

Upvotes: 2

Related Questions