Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

How to find permission level for specific user in site collection and subsite using visual studio?

share|improve this question
add comment

4 Answers 4

Getting Permission levels for a site

Adding or Removing Permissions for a user or group

Custom permission levels

If you go through above links, I am pretty sure you will figure out code you need for what you're trying to do.

Hope it helps.

share|improve this answer
add comment
up vote 1 down vote accepted

Found Solution..

public static string FindPermissionLevelForUser(string loginname, string strSite)

    {
        string strValue = string.Empty;
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(strSite))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        string spreturnUser = string.Empty;

                        try
                        {
                            SPUser user = web.Users[loginname];
                            SPRoleAssignment currentUserRole = web.RoleAssignments.GetAssignmentByPrincipal(user);


                            foreach (SPRoleDefinition role in currentUserRole.RoleDefinitionBindings)
                            {
                                strValue += role.Name + ", ";
                            }
                        }
                        catch (Exception)
                        {
                            //if user in group
                            SPGroupCollection groupColl = web.Groups;

                            foreach (SPGroup group in groupColl)
                            {
                                try
                                {
                                    SPUser user = group.Users[loginname];
                                    SPRoleAssignment currentUserRole = web.RoleAssignments.GetAssignmentByPrincipal(group);

                                    foreach (SPRoleDefinition role in currentUserRole.RoleDefinitionBindings)
                                    {
                                        strValue += role.Name + ", ";
                                    }
                                }
                                catch (Exception)
                                {

                                }
                            }

                        }
                    }
                }
            });
        }
        catch (Exception ex)
        {

            return string.Empty;

        }
        return strValue;
    }
share|improve this answer
add comment

You can get the permissions for current user using this code

SPBasePermissions bp = 
SPContext.Current.Web.GetUserEffectivePermissions
    (SPContext.Current.Web.CurrentUser.LoginName);
share|improve this answer
add comment

Already answered for the SharePoint server side objects. Just in case if you wish to find out for client side code for getting permission level of the group please refer the following link. It is similar to the server side code but you can control when to put the code into the wire. http://social.technet.microsoft.com/wiki/contents/articles/24087.how-to-get-the-permission-levels-associated-with-sharepoint-user-groups-using-client-object-model-in-netc.aspx

share|improve this answer
1  
This answer needs more details, it is too dependent on the link (if the link breaks it will be of no help in the future) –  Robert Lindgren Apr 22 at 18:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.