Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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
)

Parameters

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)
    {
        oGroup.RemoveUser(oUser);
    }
}
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.

Show:
© 2015 Microsoft