SharePoint Search Results: Adding a link to the view properties page of a document

The out-of-the-box SharePoint search results web part doesn't provide a way to get to the View Properties page for items in a document library. The search results provide a direct link to the document which will open a document in default editor registered within windows.

In the screen shot below notice that both the hyperlinked title (shown in the tool tip) and the url displayed both link to the actual document and not to the View Details page.

The goal is to generate a hyperlink that will allow the user to navigate to the properties display form for documents.

Clicking "View Properties" will take the user to the following page:

Step 1: Add a managed property for the integer ID of list items.

In order for the solution to work properly we must first create a Metadata Property Mapping for the ID of list items. SharePoint out-of-the-box does not include these identifiers in its search index.

Open the SSP

Click Search Administration

Under Queries and Results, click Metadata properties.

Click Crawled Properties:

Search for ows_id. Then edit the crawled property.

Select the checkbox at the bottom of the page to include the property in the search index:

Return to the Metadata Property Mappings screen by clicking on Metadata properties on the left side of the page.

Step 2: Add the Metadata property to the search results web part

Now that the metadata property has been added to SharePoint we now need to make the property available to the search results web part. In my example I've added the search and search results web parts to a web part page but the same steps apply if you are editing the search results web part in the search center.

Open your search results page in edit mode.

Locate the search results web part and click Modify Shared Web Part

In the Results Query Options section, open the editor for the Selected Columns property:

Add a reference to the ListItemId property as follows:

<ColumnName="ListItemID"/>

At this point the custom Metadata property we created will now be retrieved with every search query. The value will come back in the xml returned by the query servers and is just begging to be displayed somewhere on the page.

Step 3: Modify the XSL to display the hyperlink to the View Properties page.

The next step it to create a hyperlink to the View Properties page using not only the custom ListItemId Metadata property but also several other properties already available to us: url, sitename, and contentclass.

Click the XSL Editor button in the web part properties panel.

Copy the contents of the editor and paste into an XSL editor like Visual Studio .NET or any text editor.

Near the bottom of the XSL file paste in the following template definition just prior to the </xsl:stylesheet> tag:

This template first checks to see if the item is part of a document library. If so, it parses out the document library name and then builds up a URL pointing to the View Properties page and outputs a hyperlink to the page.

Important note: This link is hard-coded to point to the out-of-the-box View Properties page. If document libraries have custom View Properties pages, this solution will need to be modified.

The last step is to include a call to the new StyleSheet template. In my example, I've placed the call just after the rendering of the modified date:

Step 4: Deploy and test

Now that the XSL StyleSheet has been modified the last step is to copy the XSL back into the web part property and save your changes. Submit a simple search for documents and verify the View Properties link appears after the date.

Special thanks to Jeremy Jameson for providing the idea and starter code for this solution.