SPRoleDefinitionBindingCollection Class
Defines the role definitions that are bound to a role assignment object.
Microsoft.SharePoint.Administration.SPAutoSerializingObject
Microsoft.SharePoint.SPBaseCollection
Microsoft.SharePoint.SPRoleDefinitionBindingCollection
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
If a user has both the Full Control and Contribute roles, the role assignment for the user includes these two role definitions in the role definition binding collection.
To get the collection of role definitions that are bound to a role assignment, use the RoleDefinitionBindings property of the SPRoleAssignment class. Use the Add method to add a role definition to the collection.
Use an indexer to return a single item from the collection. For example, if the collection is assigned to a variable named myRoleDefinitionBindings, use myRoleDefinitionBindings[index] in C# or myRoleDefinitionBindings(index) in Visual Basic, where index is either the index number of the item in the collection or a string that contains the name of the role definition.
When working with the SPRoleDefinitionBindingCollection class it is helpful to combine it with CommaDelimitedStringCollection as demonstrated in the below:
var collection = new CommaDelimitedStringCollection();
SPWeb web = SPContext.Current.Site.RootWeb;
SPList list = web.Lists["Test"];
SPRoleDefinitionBindingCollection permCollection = list.Items[0].AllRolesForCurrentUser;
foreach (SPRoleDefinition def in permCollection)
{
collection.Add(def.Name);
}
if (collection.Count != 0)
{
//do stuff
}
Adam Buenz
SharePoint Foundation MVP - http://www.sharepointsecurity.com
- 10/12/2010
- Adam Buenz - MVP