Search code examples
sharepointuser-management

How to purge specific users/groups from a SharePoint site collection?


I am trying to write a utility to find/delete specific users and groups from a SharePoint site collection. At this point I'm using the SiteUsers property of the SPWeb class to do the job, but I'm wondering: why isn't there a similar property in the SPSite class? This seems completely counter-intuitive to me (though at this point nothing about SharePoint surprises me anymore).

Is there a better way to do what I'm trying to do?

Related: SharePoint - Get a list of current users


Solution

  • Unfortunately, I can't really answer WHY it ended up that way... :) it is a fact of SharePoint that you have to call SPSite.OpenWeb() or SPSite.RootWeb and then use the SPWeb to get at SiteUsers. I think the way you are doing it using the object model is fine.

    If you switch to use SharePoint's web services you could use these two methods: RemoveUserFromSite and RemoveGroup.