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: SharePoint - Get a list of current users

ekad
  • 14,436
  • 26
  • 44
  • 46
Jacobs Data Solutions
  • 4,850
  • 4
  • 33
  • 38

1 Answers1

1

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
  • 7,046
  • 1
  • 32
  • 54
  • 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 Aug 05 '10 at 00:32
  • 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. – Jacobs Data Solutions Aug 05 '10 at 12:56
  • 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 Aug 05 '10 at 13:59