简体   繁体   中英

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#?

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
        }
    }
}

Try SPWeb.GetUserEffectivePermissionInfo

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM