Export (0) Print
Expand All
Expand Minimize
1 out of 4 rated this helpful - Rate this topic

SPWeb.SiteGroups property

Gets a collection that contains all the groups in the site collection.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
[ClientCallableAttribute]
public SPGroupCollection SiteGroups { get; }

Property value

Type: Microsoft.SharePoint.SPGroupCollection
A collection of SPGroup objects that represent the groups in the site collection.

The following code example uses the SiteGroups property to return the collection of groups in the current site collection, and also displays the name of each group.

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

using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    SPGroupCollection collGroups = oWebsite.SiteGroups;
    foreach (SPGroup oGroup in collGroups)
    {
        Response.Write(SPEncode.HtmlEncode(oGroup.Name) + "<BR>");
    }
}
NoteNote

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 Disposing Objects.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.