views:

19

answers:

1

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: http://stackoverflow.com/questions/329535/sharepoint-get-a-list-of-current-users

+1  A: 

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.

Kit Menke
As each Web can have different users, having the remove users in the SPSite and the add users in the web would also be counter intuitive. Having both objects remove users would leave the man with two watches wondering what time it is.
Nat
That's my whole point. Instead of having a "SiteUsers" property on SPWeb why didn't they just put an "AllUsers" property on SPSite? It makes no sense whatsoever to me.
Repo Man
I agree, it doesn't really make sense to me either... especially when you think of the SPSite as representing the entire collection of SPWebs. Maybe because the users belong to the root SPWeb rather than the site collection as a whole? Once they belong to the root, then the users collection cascades to the sub-SPWebs.
Kit Menke