Partilhar via


SPWeb.Groups Property

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

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public ReadOnly Property Groups As SPGroupCollection
    Get
'Usage
Dim instance As SPWeb
Dim value As SPGroupCollection

value = instance.Groups
public SPGroupCollection Groups { get; }

Property Value

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

Examples

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 webSite As SPWeb = SPContext.Current.Site.OpenWeb("Website_URL")
    Dim groups As SPGroupCollection = webSite.Groups

    For Each group As SPGroup In groups
        Response.Write((SPEncode.HtmlEncode(group.Name) + "<BR>"))
    Next group
End Using
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>");
    }
}

Note

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.

See Also

Reference

SPWeb Class

SPWeb Members

Microsoft.SharePoint Namespace

SiteGroups