SPGroupCollection.Remove Method (String)

Removes the group with the specified name from the collection.

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

Syntax

'Declaration
Public Sub Remove ( _
    name As String _
)
'Usage
Dim instance As SPGroupCollection
Dim name As String

instance.Remove(name)
public void Remove(
    string name
)

Parameters

  • name
    Type: System.String

    A string that contains the name of the group to be removed.

Exceptions

Exception Condition
SPException

The group collection is read-only.

Examples

The following code example removes a specified group from the current site collection.

Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
Try
    Dim myGroups As SPGroupCollection = webSite.SiteGroups
 
    myGroups.Remove("Group_Name")
Finally
    webSite.Dispose()
End Try
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
{
    SPGroupCollection collGroups = oWebsiteRoot.SiteGroups;
    collGroups.Remove("Group_Name");
}

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

SPGroupCollection Class

SPGroupCollection Members

Remove Overload

Microsoft.SharePoint Namespace