SPWeb.RoleAssignments Property

Gets the collection of role assignments for the Web site.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

Public ReadOnly Property RoleAssignments As SPRoleAssignmentCollection
    Get

Dim instance As SPWeb
Dim value As SPRoleAssignmentCollection

value = instance.RoleAssignments
public SPRoleAssignmentCollection RoleAssignments { get; }

Property Value

Type: Microsoft.SharePoint.SPRoleAssignmentCollection
An SPRoleAssignmentCollection object that represents the role assignments.

Implements

ISecurableObject.RoleAssignments

Examples

To retrieve the actual role assignments for users and user groups for a specific Web site, use the folling code


private void AddWebSiteRoleAssignmentNodes(SPWeb oWeb)
{ 
    try
    {
        if (oWeb.HasUniqueRoleAssignments)
        {
            SPRoleAssignmentCollection oRoleAssignments = oWeb.RoleAssignments;

            foreach (SPRoleAssignment oRoleAssignment in oRoleAssignments)
            {
                SPPrincipal oPrincipal = oRoleAssignment.Member;
                try
                {
                    // To retrieve Users having explicit permissions on the WebSite
                    SPUser oRoleUser = (SPUser)oPrincipal;
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }
                try
                {
                    // To retrieve User-Groups having permissions on the WebSite
                    SPGroup oRoleGroup = (SPGroup)oPrincipal;

                    if (oRoleGroup.Users.Count > 0)
                    { 
                        string strGroupName = oRoleGroup.Name;
                        // Add code here to retrieve Users inside this User-Group
                    }
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }
            }
        }
    }
    catch (Exception ex)
    {
        string msg = ex.Message;
    }       
}

See Also

Reference

SPWeb Class

SPWeb Members

Microsoft.SharePoint Namespace