SPGroup class

Represents a group on a SharePoint Foundation Web site.

Inheritance hierarchy


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


Public NotInheritable Class SPGroup _
    Inherits SPPrincipal
Dim instance As SPGroup
public sealed class SPGroup : SPPrincipal


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 collection of groups owned by a user, or the SiteGroups property of the SPWeb class to return all the groups in the site collection.

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

Every group can be represented by an SPMember object and has a unique member identifier (see ID property). The following example assigns a group to an SPMember object:

SPMember oMember = oWebsite.SiteGroups["Cross-Site_Group_Name"];

For general information about groups and security, see Authorization, users, groups, and the object model in SharePoint 2013.


The following code example changes the name, owner, and description of a group in a site collection.

Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
    Dim myGroup As SPGroup = webSite.SiteGroups("Original_Name")
    myGroup.Name = "New_Name"
    myGroup.Owner = webSite.Users("Domain_Name\User")
    myGroup.Description = "Description"
End Try
using (SPWeb oWebsite = SPContext.Current.Site.RootWeb)
    SPGroup oGroup = oWebsite.SiteGroups["Original_Name"];
    oGroup.Name = "New_Name";
    oGroup.Owner = oWebsite.Users["Domain_Name\\User"];
    oGroup.Description = "Description";


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.

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also


SPGroup members

Microsoft.SharePoint namespace