Tangiest
Tangiest

Reputation: 44627

Determine the SharePoint Sites and Webs That A Specified User Can Access Programmatically?

I need to determine the sites and webs that a specified user can access in a SharePoint web application via the SharePoint API. Note the specified user is different from the current user that is calling the code. I initially was thinking of making use of the PortalSiteMapProvider, but it does not offer an option to change the user context in which it is built up. Can anyone offer any alternatives to this?

Thanks, MagicAndi

Upvotes: 0

Views: 1134

Answers (3)

Jacobs Data Solutions
Jacobs Data Solutions

Reputation: 4930

Not the most efficient solution to this problem, but you can iterate through all the site collections / webs in the web application and then call:

web.DoesUserHavePermissions(userID, SPBasePermissions.Open)

where "web" is a SPWeb object and userID is "DOMAIN\user.name" of the user you are checking access permissions for. Do it within a RWEP and make sure you dispose of your SPSite/SPWeb objects correctly.

Upvotes: 1

Tangiest
Tangiest

Reputation: 44627

One possible approach is to make use of impersonation to determine the sites and webs that a specific user (other than the current user) can access via the PortalSiteMapProvider. A method for impersonating another user in a SharePoint context is described here:

http://blackninjasoftware.com/2009/04/09/how-to-programmatically-impersonate-users-in-sharepoint/

Upvotes: 0

IrishChieftain
IrishChieftain

Reputation: 15253

You could use the Webservices API:

Determining User's role in a SharePoint site/workspace using the webservices API

Upvotes: 2

Related Questions