Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Groups property
Collapse the table of content
Expand the table of content

SPWeb.Groups property

Gets a collection that contains all the groups for the website.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPGroupCollection Groups { get; }

Property value

Type: Microsoft.SharePoint.SPGroupCollection
A collection of SPGroup objects.

The following code example uses the Groups property to return the collection of groups for a specified site in the current site collection.

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.Groups;
    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.

Show:
© 2015 Microsoft