Represents a group on a SharePoint Foundation Web site.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
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.
SPMember oMember = oWebsite.SiteGroups["Cross-Site_Group_Name"];
For general information about groups and security, see Authorization, Users, and Groups.
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 Try Dim myGroup As SPGroup = webSite.SiteGroups("Original_Name") myGroup.Name = "New_Name" myGroup.Owner = webSite.Users("Domain_Name\User") myGroup.Description = "Description" myGroup.Update() Finally webSite.Dispose() End Try
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.