Partager via


SPWeb.SiteGroups Property

Gets the collection of cross-site groups for the site collection.

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

Syntax

Public ReadOnly Property SiteGroups As SPGroupCollection
    Get

Dim instance As SPWeb
Dim value As SPGroupCollection

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

Property Value

Type: Microsoft.SharePoint.SPGroupCollection
An SPGroupCollection object that represents the groups.

Examples

The following code example uses the SiteGroups property to return the collection of groups for 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 webSite As SPWeb = SPContext.Current.Site.OpenWeb("Site_Name")
    Dim myGroups As SPGroupCollection = webSite.SiteGroups

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

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 Best Practices: Using Disposable Windows SharePoint Services Objects.

See Also

Reference

SPWeb Class

SPWeb Members

Microsoft.SharePoint Namespace