Share via


SPRole Class

The SPRole class represents a site group in Microsoft Windows SharePoint Services.

System.Object

   Microsoft.SharePoint.SPMember

      Microsoft.SharePoint.SPRole

Public Methods

The following table shows the public methods of the SPRole class and a brief description of each.

Name Description
AddGroup(Microsoft.SharePoint.SPGroup) Adds the specified cross-site group to the site group.
AddUser(Microsoft.SharePoint.SPUser) Adds the specified user to the site group.
AddUser(String, String, String, String) Adds to the site group the user specified by user name, e-mail address, display name, and notes.
RemoveGroup Removes the specified cross-site group from the site group.
RemoveUser Removes the specified user from the site group.
ToString Returns the name of the site group.
Update Updates the database with changes made to the site group.

Public Properties

The following table shows the public properties of the SPRole class, the data type of each property, and a brief description of each.

Name Data Type Description
Description String Gets or sets the description for the site group.
Groups Microsoft.SharePoint.SPGroupCollection Gets the collection of cross-site groups that belong to the site group.
ID Int32 Gets the member ID for the site group.
Name String Gets or sets the name for the site group.
ParentWeb Microsoft.SharePoint.SPWeb Gets the parent site for the site group.
PermissionMask Microsoft.SharePoint.SPRights Gets or sets the rights used for the permission mask of the site group.
Type Microsoft.SharePoint.SPRoleType Gets the type of the site group.
Users Microsoft.SharePoint.SPUserCollection Gets the collection of users that belong to the site group.
Xml String Gets the site group in XML format.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

Use the Roles property of the SPUser, SPGroup, or SPWeb class to return an SPRoleCollection object that represents the collection of site groups for a user, cross-site group, or site. Use an indexer to return a single site group from the collection. For example, if the collection is assigned to a variable named mySiteGroups, use mySiteGroups[index] in C#, or mySiteGroups(index) in Visual Basic .NET, where index is either the index number of the site group in the collection or the display name of the site group.

Every site group has a unique member ID, has the permissions associated with that membership, and can be represented by an SPMember object. The following example assigns a site group to an SPMember object:

SPMember myMember = site.Roles["Site_Group_Name"];

Site groups are defined per Web site. Users assigned to the Administrator site group are administrators only for a particular Web site. To perform any administrative tasks that affect settings for all Web sites and virtual servers on the server computer, a user must be an administrator for the server computer (also known as a local machine administrator) or a member of the SharePoint administrators group, rather than a member of a site's Administrator site group.

The Administrator and Guest site groups cannot be modified or deleted.

A site group can be assigned permissions directly, while a cross-site group needs to be added to a site group in order to be assigned permissions. Cross-site groups and users can be members of site groups. For general information about site groups and security, see Security, Users, and Groups Overview.

For information about the default site groups that are available in Windows SharePoint Services, see the SPRoleType enumeration.

Example

The following code example removes a specified user from a site group in all the subsites under a site.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security