Question

I have a challenge. On our SharePoint environment, we want to have one page, with all sites where the current user has contribute permissions on. This way, he knows where he can collaborate.

I already found a kind of way to do it with web services on following site http://sympmarc.com/2010/01/29/determining-if-a-user-is-in-a-permission-group-with-sharepoints-web-services/ but I should find a way to do this for all sites in my site collection/farm.

What should be the best approach to do this you guys think?

UPDATE: based on the comments I want to let you know it's an on-premise environment. And it should be great to have a solution that shows all sites of all site collections in the web application. Even it's on-premise, a webservice/spservices solution instead of c# would be great :)

Thanks!

No correct solution

OTHER TIPS

You can check the permissions of a user using the 'DoesUserHavePermissions' method. See code sample below.

However in order to return all the sites you need to loop over all the sites and site collections. This is very resource intensive! I would not recommend it on a webpage or when the code will execute a lot. On a webpage you risk getting slow page responses and time-outs.

In a timerjob that runs only a few times a week or in a one-off script I might consider it.

Personally, I would look into a search solution and some form of (custom) caching.

  • Create a content type with the needed info (user, permission).
  • For each site, let a timerjob update a (hidden) list with items based on this content type
  • Use search to get the information. (Filter on contenttypeid and user)

This is sort of a workaround. Not realtime, but it will be faster than looping over all sites. And more importantly will use a lot less resources.

Make sure you configure the scheduling of the timerjob and the search crawl job correctly.

using (SPSite site = new SPSite("http://localhost"))
{
    using (SPWeb web = site.OpenWeb())
    {                  
        SPBasePermissions permissionToCheck = SPBasePermissions.ManageLists;

        string login = web.CurrentUser.LoginName;
        if (web.DoesUserHavePermissions(login, permissionToCheck))
        {
            //user has permissions.
        }       
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top