SPRoleCollection Class

The SPRoleCollection class represents a collection of SPRole objects.

System.Object

   Microsoft.SharePoint.SPBaseCollection

      Microsoft.SharePoint.SPRoleCollection

Public Methods

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

Name Description
Add Creates a site group with the specified name, description, and permission mask in the collection.
GetByID Returns the site group with the specified member ID.
GetCollection Returns the site groups specified by an array of names from the collection.
GetSpecialRole Returns a system site group specified by its type.
Remove(Int32) Removes the site group at the specified index in the collection.
Remove(String) Removes the site group with the specified name from the collection.
RemoveByID Removes the site group with the specified ID from the collection.

Public Properties

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

Name Data Type Description
Count Int32 Gets the number of site groups in the collection.
Item(Int32) Microsoft.SharePoint.SPRole Gets the site group object at the specified index in the collection.
Item(String) Microsoft.SharePoint.SPRole Gets the site group object with the specified name from the collection.
Web Microsoft.SharePoint.SPWeb Gets the parent site for the collection of site groups.
Xml String Gets the collection of site groups 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.

Example

The following code example adds all the users of a site to a specified site group for all the subsites under the 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