Last Update: Sep 04, 2024 | Published: Jun 03, 2014
This article is going to demonstrate create a no-code solution to a simple problem in SharePoint 2013, which is how to display limited information to a user based on their permissions. More specifically, this solution will be a web page that shows a user a directory of all of the project sites within SharePoint that the user has permissions to view.
Like any good solution, we are going to need a problem! It only makes for a good use of your valuable time and effort to begin with trying to solve a problem with your solutions.
The business need we’re trying to solve with this solution is this: We need a place for people to find all of the project sites that they have access to. It needs to automatically update – that is, new sites need to be added to the list without somebody going into the list and updating manually.
At the heart of this approach is the SharePoint search service. We’ll be making some calls to the search service to get the list of sites. This takes care of one of our business needs – avoiding manual updates.
This search will be performed through a web part. However, instead of prompting the user to enter in search terms, we’re going to configure a web part to return a specific search query.
The specific search query we’re going to run will be created as a result source, which can be used like search result building blocks. If you only ever wanted to perform a search in one place, you could just enter that query directly into the web part. But by using a result source we can reuse that search result easily, in multiple places and in multiple web parts. And if we need to make a change to the result source, all of the web parts that use the result source are updated automatically.
Are you ready to begin? We’ll have configuration items in a few places, so let’s get started.
Oh, now you’ve done it. You’ve started using the Query Builder. You just opened up a Swiss Army knife of search query goodness. The query builder lets you see the results that you get while you’re building the search query to make sure that your results match your expectations, and it gives you the tools to build exactly the kind of search you want. You’ll want to spend a lot of time exploring the query builder because you’ll be back here a lot now that you’ve seen it.
This adds contentclass:STS_Web into the query text. That will give us any webs in our search results, but in my testing I’ve gotten poor results with only this search term, with only subsites being returned and not the root sites in a site collection.
Note: Hopefully you’re seeing that what I’m showing you is a really specific use, and it’s not likely that this is exactly what you were going to use. It should be adapted for your use case. You might want sites of a different template, or you might want no template restrictions at all and try to get a totally different search result.
You can place the web part either into a web part zone, or into a content section of the page.
Now that the search web part is added to the page, click on the web part. Once the web part is selected, a “Web Part” tab appears on the ribbon. Select the Web Part tab of the ribbon, then click on “Web Part Properties”.
It’s worth mentioning the display templates at this point because it will determine how the results are formatted. Since we’re just getting started, we’ll leave them as default, but you should come explore the different display templates to see which style fits you best.
If your site is in only one language, it doesn’t make sense to have the language selection option sitting out there. You can make it go away by expanding the Settings and removing the check in the Show language drop-down. Then click OK on the Web Part Properties
While it might not seem like we’ve done a lot, if this is the first time you’ve used a result source and a search web part on a page, then you’ve taken some huge steps. You now have a page that meets our initial requirements: a simple place where anyone can come and see the project sites that they have access to. Since the search is still being run under the context of a user running the page, only sites that the user has read permissions to will be returned in the results. And since the search results are being returned in real-time when the page loads, if somebody adds in a project site anywhere in the SharePoint farm you’ll see it the next time the search service performs an incremental search.
Have you made yourself a project site page? How has it worked for you? Let us know, or feel free to ask a related question in the comments below.