How to build a company directory app in 5 minutes (using Search and User Profiles)

A customer asked me about setting up a typical type of company profile application where you click on a letter and you can see the employees with that last name in a list. The speed at which I was able to fashion a completely functional application using just user profiles and search features caught me by surprise. I have seen these kinds of apps in SharePoint before, usually taking multiple components and hundreds of lines of code. This solution will take you about an hour. Ok, my title said 5 minutes but it is an exceedingly easy to build app.

Caveat, there are a few pre-requisites.

1. You have to have a user profile service and some user profiles generated. The more complete the better of course.

2. You have to have a search service running and configured.

3. You have to be familiar enough with web parts and such to do this.

Step 1 – create a blank page on your site to host the 2 web parts you are going to need. You can use the wiki style page or a web part page

Step 2 – Add a Search Results web part to the page. Also add a content editor web part or just put the HTML onto the wiki page directly, creating a 13 column, 2 row table to hold the alpphabet letters. Something like figure 1 below.


Step 3– edit the search results web part as follows:

  • Edit the web part. In the tool pane select the change query button
  • In the query builder window that pops up, fill it out as follows
    • Select the query (local people results)
    • Remove the {SearchBoxQuery} filter from the Query text editor field
    • Add a property filter LastName:{QueryString:MyParameter1} – note: the parameter name can be anything, it does not have to be “MyParameter1”, but whatever you use in this query you will need to use in the HTML later)
      • You can use the dropdown boxes to create this fitler or just type it into the editor field directly. The results is shown in the image below
    • Click OK and stop editing the web part

Step 4– add HTML to the letters created in step 2. For each letter, add a link pack to the page with a query string parameter using the name defined in step 3 (MyParameter1 for this sample) and a value of the letter and a wildcard character…

Here is a sample for letters A and B. note Company%20Directory.aspx is the name of the page where we are adding these web parts

<a href=”/SitePages/Company%20Directory.aspx?MyParameter1=A%2a”>A​</a>

<a href=”/SitePages/Company%20Directory.aspx?MyParameter1=B%2a”>B</a>

When a user clicks on a letter, it will reload the page, sending the parameters of the last name first letter and a wildcard. This will cause the search results web part to show all user profiles that begin with the letter in the query string.

That’s it. You may want to add a few visual embellishments for a full production app, but this is a fully functional directory if you have a decently filled out or synced user profile.


Limit Search Results to the current and child site in SharePoint 2013

How to limit search results to the current and sub-sites in SharePoint 2013

Here is a quick hint for the use case where you want to position a search box and/or results to only show results that may reside in the current site or all sites below it.

#1 – Create a result source at whatever level you wish. If you set it at the search service level, you can use this results source over and over throughout the entire farm. It can also be set for a site collection or an individual site. You need to figure out at what level do you want to reuse it. Just copy the default result source and modify it as follows.

#2- Use the query transform capability to modify the results source by adding the following modification. Add the property path contains “This site”. It will look like this in the query text


Since you are specifying “contains”, it will include the current site and all subsites since all subsites will contain the path of the parent. All other results not in or below the current site will be excluded because they will not have this path.

This screen shot shows the whole thing. I made this at the site collection level. Had I done it at the farm (search service) level, it can be used anywhere in the farm.

SharePoint 2013 –

If you are getting these errors or users are reporting this error when trying to get access to a site, this might be your problem. Each site collection can set its own email address for access requests, if you allow them. Here is how to fix it.

  1. Go to the top level site of any site collection. Click on Site permissions on the settings page.



  2. On the page that comes up, click on Access Request Settings.


  1. Change the default value to whatever email you want to receive the requests. is the default. This is why you are getting the errors.



Cannot delete Host header site collections in Central Admin

I was recently trying to create some host header site collections to my new SharePoint 2013 farm. My first 2 attempts failed because I did not have enough rights to the content DB where the site collections would be created.

s—spsite : Cannot open database “lISS_Content_Intranet” requested by the 
gin. The login failed. 
gin failed for user ‘CORP\SPINSTALL’. 
1 line:1. char:1 
iew—spsite ‘” —owneralias 
t orp\spinstal... ____________________ 
+ Categorylnfo : InualidData: (Microsoft.Share. . .SPCndletNewSite: 
SPCndletNewSite) [New—SPSite], SqlException 
+ FullyQualifiedErrorid : tlicrosoft.SharePoint.PowerShell.SPCndletNewSite

Once I added the proper rights, I tried the command again, only to be told that those site collections already existed. When I go to the view all site collections page in Central Admin I see my phantom site collections in the list. Highlighting it however, reveals no metadata on the right as you would expect. compare the below images. the first is my phantom site collection. the second is a proper one.



I tried to delete these rogue entries , only to be told they did not exist. Clearly a bug here, but how to fix it? I stumbled upon 1 simple solution while working on a different issue. Follow these basic steps (Dont try this if you are in the middle of an upgrade. this assumes you dont have any upgradeable databases)

I have a mix of powershell and central admin here. You could do this all with powershell or all with the UI. This is just how I did it.

1. create a test web application. you can delete it when you are done.
2. in central admin, on the content database page remove the content db from the new test web app (or use powershell)
3. now remove the content db from your actual web app where you are having the issue using the same process as step 2
4. attach your content db with the rogue site collection entries from your actual web app to the test web app. here is a powershell command (you can do this in the UI as well)

Mount-SPContentDatabase “MyDatabase” -DatabaseServer “MyServer” -WebApplication http://sitename

5. now you can browse to the list of site collections in central admin under this test web app and you should see that the phantom site collections are gone.

6. once again, remove the content db from the test web app

7. once again, attach the content db back to the original web app and you should be good to go

8. delete the test web app and unused content database created with it.

It may be that just removing and reatttaching the content db from the original web app may be sufficient without the need for the test web app. that may be worth a try first. I was researching another issue and found to my surprise that my phantom site collection issue had been solved.

error opening documents SharePoint 2013

I ran across an odd error the other day with some users of SharePoint 2013. When they tried to open any document from a library they would get an error of page not found and the URL looked like this….

ms-word:nft|u| <URL of site>/Forms/<library name> |s| <url of site>

In this case, the culprit was having Office 2010 and installing a 2013 office component as well. In this case SP designer 2013. The fix was removing SPD 2013 and repairing office.

Does this mean you cant have SPD 2013 and Office 2010? This is probably going to be a common scenario for people that are on new sharepoint but not new office. I dont have an answer at this point other than to say I had a similar issue with outlook and found that installing 2013 first, then adding back in 2010 components (outlook in this case) seems to work for me. I run SPD 2010, 2013, Office 2013 except outlook and outlook 2010 on my machine and have no trouble. I installed office 2013, then uninstalled just outlook, then re-installed outlook 2010 in my case. I already had both versions of SPD on my machine at the time.