Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

3 Answers 3

up vote 1 down vote accepted

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. ;-)

share|improve this answer
add comment

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).

share|improve this answer
add comment

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.

http://weblogs.asp.net/bsimser/archive/2006/03/13/440169.aspx

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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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