Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SPGroup class

Represents a group on a SharePoint Foundation Web site.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
[SubsetCallableTypeAttribute]
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.

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";
    oGroup.Update();
}
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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.