3

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

1

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.

| improve this answer | |
1

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;
    }
| improve this answer | |
1

You can get the permissions for current user using this code

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

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

| improve this answer | |
  • 2
    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 '14 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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