SPGroupCollection, classe
Réduire la table des matières
Développer la table des matières
Le document est archivé et les informations affichées ici peuvent être obsolètes

SPGroupCollection, classe (Microsoft.SharePoint)

Windows SharePoint Services 3
Represents a collection of SPGroup objects.

Espace de noms : Microsoft.SharePoint
Assembly : Microsoft.SharePoint (dans microsoft.sharepoint.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
public class SPGroupCollection : SPMemberCollection

Use the Groups property of the SPUser or SPWeb class to return the collection of groups for the user or Web site. Otherwise, use the OwnedGroups property of the SPUser class to return the groups owned by a user, or the SiteGroups property of the SPWeb class to return all the groups in the site collection.

To create a group in the site collection, use the Add method.

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

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

using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
    SPUserCollection collUsers = oWebsiteRoot.Users;
    SPUser oUser = oWebsiteRoot.Users["User_Name"];

    SPGroupCollection collGroupsWebsite = oWebsiteRoot.SiteGroups;
    SPGroupCollection collGroupsUser = oUser.OwnedGroups;

    foreach (SPGroup oUserGroup in collGroupsUser)
RemarqueRemarque :

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

Les membres statiques publics de ce type (Shared en Visual Basic) sont sécurisés au niveau des threads. Il n'est pas garanti que les membres d'instance soient sécurisés au niveau des threads.
© 2016 Microsoft