I want to retrieve all the users who are having any access to at least one site in a site collection. I tried using 'SPWeb.SiteUsers' and it gave me almost what i wanted. The only exception was - it also returns me the users which once had permission one some site, but their permission were revoked later.

Is there a way to get all active users having access to at least one site in a given site collection ?


There is no way to get that list. SharePoint don't even know it.

SiteUsers is the closest, but as you've already found out it includes users who has had access to a site (or items on a site) (and have used that access). But it doesn't include users who have access due to a group membership, but haven't used that access yet.

So the best would be to look in the governance document specifying who has access. ;-)


SharePoint knows that list. At least SharePoint knows which users have explicit access, which users have access via a SharePoint group, and which AD security groups have access ( either explicitly or via a SharePoint group... ).

Knowing this, you can browse all the SPSite's SPWebs ( SPSite.AllWebs ), then browse each SPWeb's SPUsers ( SPWeb.SiteUsers contains that list ), then, if the SPUser is an AD security group ( IsDomainUser == true ), you can use a third party Active Directory Add-On to browse the AD group recursively for all users within it ( check out the powershell Get-ADGroupMember cmdlet if your server farm supports it - but there are other ways to do it ).

During the browsing process ( before expanding into the AD security group tree ), you can access each SPUser's permission using the SPWeb object ( SPWeb.GetUserEffectivePermissionInfo() ) and filter the SPUsers which don't have the required permissions.

In practice, you won't get a SPUser object instance for each user having access to your site, but you will get an exhaustive list of logins & other substantial infos matching this criteria (depending on your third party tool for browsing the AD).


SPWeb.SiteUsers will fetch you all the users in that Site Collection.

SPWeb.Users is what you are looking for. It should fetch you all the active users of a perticular site.


Another thing that’s interesting is that if you did add “spsuser” to the site manually he would show up in the SPWeb.Users list above. However if you removed him, he would vanish from SPWeb.Users but he would still show up in the SPWeb.SiteUsers list. His ID # is reserved so the next user you added manually would have an ID of #6 (in the case of the site) and if you re-added “spsuser” at a later date, he would re-appear in both lists with an ID of #5.

  • SPWeb.Users is not correct option here because it would not return me the users who have permissions on a site via some group... :) – Amit Tyagi Mar 23 '12 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.