Site icon @WonderLaura

Web Part: Sites that I have access to

In many companies, there are a couple of different types of environments.  There is the “intranet” and/or the public site, and both of these types of portals contain sites with mostly one way information.  With these sites, pretty much everyone has access to everything in there.  On the other hand, there’s the “collaboration portal”.  In many cases, this is a separate web application or site collection, where users keep their collab type sites.  These sites are used heavily, and contain dynamic information.  These are usually departmental sites or sites based around a particular project.  When I say departmental sites, I mean that they are sites that only people in that department can get to, so basically there is more security involved with the collab sites, because you want people to only access their own department site, or the site related to only projects that they are involved in.

With that said about collaboration, how do people navigate through all of these sites?  Yes, many of you may have an awesome nav / taxonomy that may be very simple and obvious for the end users.  A lot of times, though, this is what I see: Each time a new collab site is created, the site members each will receive the email that is generated when they have been given permission to the site.  Or, the project manager may create the project site and send the team members the URL to the site.  In these cases, users typically rely on going back to that email in order to click the link when they need to go to that site.  Not optimal.  They also may add the site to their browser’s favorites.  Also not optimal, because there is no one cohesive way for people to know that they can access the sites that they use.

If anything so far sounds familiar, then this may be the solution for you.  This solution is a way to create a single web part that displays a simple list of all of the sites that the current user has access to.  In this example, I’ll be using SharePoint 2010, but this can also be done in 2007.  This is an enterprise only solution, because it involves using the search results web part.

At the high level, this method is nothing new, I’ll be using the search results web part.  Many other SharePoint bloggers have written or done presentations about this concept, such as Matt Bremer, Eric Shupps, Paul Galvin, John Ross, Dan Attis, Tobias Zimmergren, and many more.  I referenced many of their blogs in order to put together this one.

Here are the steps:

  1. On a blank web part page in the browser, insert the Search Core Results web part.
  2. In the web part properties, expand the Display Properties section.  Change the default results sorting to “modified date”. Change the results per page to 50 (this is up to you really, but 50 is the max).  Uncheck the box called “use location visualization”.
  3. Also in the web part properties, expand the Results Query Options section.  Change the cross-web part query ID to “Query 2”.
    In the Fixed Keyword Query box, paste the following text:
    contentclass:STS_Site contentclass:STS_Web contentClass:sts_listitem_850
    Basically what we’re doing here is to say that all we want to see in this web part is sites (STS_Site), sub-sites (STS_Web) and publishing sites (sts_listitem_850).
  4. Go ahead and click OK.  You’ll now see a nice, pretty list of all sites.  Since security trimming is built in, you’ll only see the sites that you have access to.  Now technically you could stop here, but you may want to tweak the way this web part looks…
  5. In this same web part’s properties, expand the Display Properties section, and click the <XSL Editor> button. Note that this will be grayed out if you haven’t unchecked the “Use Location Visualization” box.
  6. In the XSL Editor, paste the following code:

    <xsl:stylesheet version=”1.0″
    <xsl:output method=”xml” version=”1.0″ encoding=”UTF-8″ indent=”yes”/>
    <xsl:template match=”/”>
    <xmp><xsl:copy-of select=”*”/></xmp>

  7. Click SAVE and click OK in the web part tool pane.
  8. Now there will be a bunch of weird looking xml code on the page.  Copy all of this to your clipboard, all the way from the first <All_Results> to the end </All_Results>
  9. Open Notepad.exe and paste your clipboard into it.  <Save As> and save this file name as something like SearchResultsFile.xml, and be sure to change the Save As Type to ALL FILES.  It does need to be an XML file.
  10. Open SharePoint Designer 2010, and open your site.
  11. Click Data Sources on the left side in SharePoint Designer.  Click the XML File Connection button in the ribbon.
  12. Click Browse to navigate to the XML file that you just created.  When you select it, you will get a message something like this:

    Click OK.
  13. Then your screen will look like this.  Click OK.
  14. Open up a web part page in SharePoint Designer.  This doesn’t have to be the same temporary web part page that we used in the previous steps, but it can be… it doesn’t really matter because this one is temporary too.
  15. On the web part page, click inside a web part zone, and click the Insert tab in the ribbon.  Click the Data View drop-down box, and choose EMPTY DATA VIEW.
  16. Once you’ve put the empty data view on the page, click the middle of the web part “Click here to select a data source
  17. On the data source picker, choose the name of the new XML file you created, and click OK.
  18. Notice that now the Data Source Details pane is showing on the right side, something like this:
  19. The next thing to do is decide what fields you will want to be displayed in this new web part.  Obviously there are several choices you could look at, but for this post for simplicity’s sake, we’ll just use the “Title” of each site.  So click the Title field and click the <Insert Selected Fields as> button and choose Multiple Item View.
  20. You’ll want the title to be an actual hyperlink, so go ahead and click the name of any of the sites in your web part list.  On the Insert tab, click Hyperlink.
  21. For the address of the hyperlink, choose the URL field and click OK.
  22. Obviously at this point you could spend more time making this web part look prettier.  Here are a couple of cosmetic suggestions:
    – Sort the list alphabetically.
    – Click on Paging and choose to display all items (even though there will still be the 50 item limit in the search results web part)
    – Select the cell with the word “title” in it, and delete that cell
    – IF you have multiple web apps such as intranet, public and collaboration, and you only want to show sites that exist in say, the collab portal, you could add a filter here, to say that the URL “contains” and put the URL of the root of the portal. (using a search scope is another option and is mentioned later)
  23. Anyway, we’re almost there.  SAVE this web part page, and open it in the browser.
  24. In the web part properties in the browser, click the XSL Editor button.

    Select ALL of the text in there and copy it to the clipboard.
  25. Now, go back to that original web part we started with, the Search Core results web part in the browser.  In this web part’s properties, expand the Display Properties section, and click the <XSL Editor> button.  Erase what’s in there, and PASTE the clipboard in.
  26. SAVE and click OK to save the web part.  DONE
  27. Okay, so now you can export this web part and then cleanly import it onto any site or page in your whole farm.


Is the 50 item limit a little restrictive for you? You can add the search paging web part to your page, so that people can click to the next page.  The only setting you need to change:  In the Miscellaneous section in the web part properties, change the Cross-Web part Query ID to “Query 2”, just as long as it is the same thing that was selected for the search core results web part in the same setting.

Search Scope

Note that if you’ve created custom search scopes in search administration, and you’d like to limit the results to only one of them, there’s another setting to note.  In the search core results web part, expand the Location Properties section, and you can just free-form type the name of the scope you’d like to use.

In Summary

All in all, this method of using the search results web part is pretty powerful.  You can use this as GLOBAL NAVIGATION, and you can use it to display a directory of people straight from “people results”.  Read the other associated blogs (listed at the top) for further ideas.  Oh, and there’s even a codeplex project out there that gives sample code for search results web parts.

Exit mobile version