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

I need to know how to detect the limited access role, when looping through role definitions for a list item.

Item in code below is a listitem, using object model (c#).

Code so far is:

SPRoleAssignmentCollection roles = item.RoleAssignments;
foreach (SPRoleAssignment role in roles)
    {
        SPRoleDefinitionBindingCollection rbc = role.RoleDefinitionBindings;
       foreach (SPRoleDefinition rdef in rbc)
        {
          RoleAssignment.RoleDefinitionBindings.Add(rdef);
        Log("Adding role definition : Name(" + rdef.Name + ") Type(" + rdef.Type + ")");
        }
    }

problem is the RoleDefinition.Type enum does not have a limited property, so how can I check if the permission is limited / restricted access?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

If you want to check if it has limited access, you can use this code:

SPRoleDefinition limitedAccessRole = SPContext.Current.Web.RoleDefinitions["Limited Access"];
foreach (SPRoleAssignment roleAssignment in item.RoleAssignments)
{
    if (roleAssignment.RoleDefinitionBindings.Contains(limitedAccessRole))
    {
        // Your limited access
    }
}  
share|improve this answer
    
Its a nice approach, I wonder if you could substitute in if rdef == limitedAccessRole, then its a sure winner. Another thing is wonder how it works on localized (non english sites). –  user879 Dec 3 '10 at 23:08
    
Yes you can change if, but you will need to itarete over roleAssigment.RoleDefinitionBindings to make the check. I didn't had any expirience in localization of permission, so I don't know. Can you post some information how to solve localization issue? –  Andriy Shvay Dec 6 '10 at 9:29
    
Please have a look at victors answer. I've edited it (i hope it will be accepted) with some localization details. It is not obvious that Guest will be resolved as Limited Access in english webs, but that is exactly the type. –  Marco Scheel Mar 1 '13 at 12:14
add comment

To get a role definition without any localization issues and without hard coding use the SPRoleType enum:

Example:

if (roleAssignment.RoleDefinitionBindings.Contains(SPContext.Current.Web.RoleDefinitions.GetByType(SPRoleType.Guest)))
{
    // Do something
}

In German the name of the role is "Beschränkter Zugriff", but in English this is called "Limited access". Hardcoding the name of the role would not work in a multi-language environment.

share|improve this answer
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.