SPGroupCollection Class

The SPGroupCollection class represents a collection of SPGroup objects.

System.Object

   Microsoft.SharePoint.SPBaseCollection

      Microsoft.SharePoint.SPGroupCollection

Public Methods

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

Name Description
Add Adds a cross-site group to the collection of cross-site groups in a site collection.
GetByID Returns a cross-site group from the collection based on the member ID of the group.
GetCollection Returns from the collection a collection of cross-site groups specified by an array of names.
Remove(Int32) Removes the cross-site group at the specified index in the collection.
Remove(String) Removes the cross-site group with the specified name from the collection.
RemoveByID Removes the cross-site group with the specified member ID from the collection.

Public Properties

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

Name Data Type Description
Count Int32 Gets the number of cross-site groups in the collection.
Item(Int32) Microsoft.SharePoint.SPGroup Gets the cross-site group object at the specified index in the collection.
Item(String) Microsoft.SharePoint.SPGroup Gets the cross-site group object with the specified name from the collection.
RetrieveAllRoles Boolean Gets or sets a Boolean value that specifies whether to preload the site groups to which every cross-site group in the collection belongs.
Web Microsoft.SharePoint.SPWeb Gets the parent site for the collection of cross-site groups.
Xml String Gets the properties of the collection as XML.

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 Groups property of the SPRole, SPUser, or SPWeb class to return the collection of cross-site groups for the site group, user, or site. Otherwise, use the OwnedGroups property of the SPUser class to return the cross-site groups owned by a user, or the SiteGroups property of the SPWeb class to return all the cross-site groups in the site collection.

To create a cross-site group in the site collection, use the Add method represented in the table above. To add a cross-site group to a site group, use the AddGroup method of the SPRole class.

Use an indexer to return a single cross-site group from the collection of cross-site groups. For example, assuming the collection is assigned to a variable named myGroups, use myGroups[index] in C#, or myGroups(index) in Visual Basic .NET, where index is either the index number of the cross-site group in the collection or the name of the cross-site group.

Example

The following code example iterates through all the cross-site groups in a site collection and deletes all cross-site groups owned by the specified user.

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