SPGroup.RemoveUser method

Removes the specified user from the group.

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

public void RemoveUser(
	SPUser user


Type: Microsoft.SharePoint.SPUser

The user to be removed from the group.

This method removes the user from the group as specified by the Users property.

The following code example removes a specified user from every group in a site collection.

using (SPWeb oWebsiteRoot = SPContext.Current.Site.RootWeb)
    SPGroupCollection collGroups = oWebsiteRoot.SiteGroups;
    SPUser oUser = oWebsiteRoot.Users["User_Name"];

    foreach (SPGroup oGroup in collGroups)

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.