SPGroupCollection.RemoveByID Method
Removes the group with the specified member ID 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 RemoveByID ( _
id As Integer _
)
'Usage
Dim instance As SPGroupCollection
Dim id As Integer
instance.RemoveByID(id)
public void RemoveByID(
int id
)
Parameters
id
Type: System.Int32A 32-bit integer that specifies the member ID of the group to be removed.
Exceptions
Exception | Condition |
---|---|
SPException | The group collection is read-only. |
Remarks
The value of the id parameter corresponds to the unique member ID for the group, which equals the ID property of the SPMember class. Use the Remove method to remove a group at a specified index in the group collection.
Examples
The following code example removes all groups that have IDs between 50 and 100 from the site collection.
Dim webSite As SPWeb = SPContext.Current.Site.RootWeb
Try
Dim myGroups As SPGroupCollection = webSite.SiteGroups
Dim i As Integer
For i = 50 To 100
myGroups.RemoveByID(i)
Next i
Finally
webSite.Dispose()
End Try
using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
{
SPGroupCollection collGroups = oWebsiteRoot.SiteGroups;
for (int intIndex=50; intIndex<101; intIndex++)
{
collGroups.RemoveByID(intIndex);
}
}
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.