Export (0) Print
Expand All
Expand Minimize

SPWeb.RoleAssignments Property

Windows SharePoint Services 3

Gets the collection of role assignments for the Web site.

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

public SPRoleAssignmentCollection RoleAssignments { get; }

Property Value

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

Implements

ISecurableObject.RoleAssignments

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;
    }       
}


Community Additions

ADD
Show:
© 2014 Microsoft