Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog



Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, Office 365 / SharePoint Online and Visual Studio 2013.

Introducing Document Link Handler for MOSS 2007 Enterprise Search

Since, I have started working with Enterprise Search, I have received many requests looking for ways to improve what we can do with documents.  The search results screen in MOSS, as flexible as it is, has always been lacking in features compared to search results of other ECM systems.  Common feature requests I have seen from clients include:  editing the document, viewing properties, linking to the folder or document library, linking to the site the document is in, zip and download, view version history, and more.  Today I am pleased to announce a simple solution which can handle many (but not all) of these common requests.

So how do we accomplish this?  I decided to build a simple ASP.NET Handler (.ashx) file to parse the URL from a document on the search results page and redirect a user to the page that he or she wanted.  Links to the handler can easily be added by modifying the XSL of the CoreResultsWebPart.

The code of the handler is pretty simple.  I take the URL passed via query string, split it to get the filename and the path and then I open an SPWeb object that references that site.  Once I have access to an SPFolder and SPFile object for the document, I can determine URLs for the document library and folder.  Take a look at the code if you are interested.  It might need some optimization, but it is a good starting point.

Installation is simple.  Install the included .wsp file contained in the package folder.   The syntax is listed in the readme.txt file if you need it.  This will copy the DocumentLink.ashx file into your layouts folder.  To add the links to your search results, go to the results page of your search center and edit your CoreResultsWebPart.  In the Data View Properties, click on the XSL Editor button.  Replace the XSL in the window with the contents of the included SampleCoreResults.xslt file.  If you have already made customizations to this file or you only want certain links, you may copy just the lines you need from the readme.txt file.

After you have changed the XSLT, apply the changes and execute a search query.  If you receive an error, then your XSL is probably malformed.  Open the XSL with Visual Studio if necessary to help find the error.  If all goes well, you should have search results that look like the one below.  Note, that these links will only show up for search results that are documents (IsDocument:1).  This works together in conjunction with my post earlier this week on adding an edit document link to search results.


The binaries and source code are available at CodePlex.  If you have any issues, please log them there on the Issue Tracker.  If you have any idea of other kinds of links we can provide off of a document library, please leave a comment.  This can also be used with the Wildcard Search web part.  Hopefully this will help many others out there deliver even richer search solutions to their customers.  Thanks.

Document Link Handler for MOSS 2007 Enterprise Search



China & Tibet said:

Pingback from  China & Tibet

November 2, 2008 6:32 AM

Extending the Document Link Handler for MOSS 2007 Enterprise Search « Devology Solutions Blog said:

Pingback from  Extending the Document Link Handler for MOSS 2007 Enterprise Search «  Devology Solutions Blog

April 20, 2009 2:56 PM

Raghu said:

Can we make this as a dropdown what we see i.e. Title with edit menus?

October 20, 2010 3:34 PM

Tom said:


I installed your Doc Link handler. Edit is working fine, but on click on any other option (History, Properties and etc.) I am getting "File not found" message.

I re-checked and handler is there (layouts/tempaltes/dotnetmafia folder). Any ideas?


March 10, 2011 1:38 AM

Bill said:

I made some minor changes, did a build, followed your readme and it all work just peachy. Exactly what I wanted. Thanks Corey.

May 18, 2011 7:22 PM

Bill said:

Well, I thought everything was peachy after installing this solution. My problem is with the View/Edit Properties. Sometimes it works, sometimes the browser throws a 404-page not found error. If I look at the link for the redirect, it looks fine and I can input this link in the browser and it opens the document of reference. There is no rhyme or reason that I can detect as to why some work and some don't. The go to folder and version history links work 100%, just the view properties fails most of the time(but not all). I am stumped. Any suggestions?

May 20, 2011 12:57 PM

CoreyRoth said:

@Bill Maybe there is an issue with the way I am parsing the URL on those documents.  You rebuilt it on your own correct?  Have you tried debugging it and seeing if there is an exception.

May 20, 2011 1:18 PM

Bill said:

Corey, thanks for the reply. I will need to wait till after hours to really mess around with de-bugging, and this is my first stab at any SharePoint C# stuff, I mostly write form applications. So to be honest, and to admit my stupidity, I have no idea how to debug a web application. I looked at your code, it looks solid to me when parsing/building the URL. This is not a show stopper, the business insisted on a way to get to the parent folder and that works perfect, this would just be an added bonus. Any advice on de-bugging would be much appreciated.

Again, thanks for the reply.

May 20, 2011 1:54 PM

Brian said:

Hi Corey,

Is this also easily done in SharePoint Standard 2010 Search?  I have been looking, without luck, for this exact kind of answer (only with an additional link to "E-Mail a Link" with those other actions).

October 28, 2011 12:27 PM

CoreyRoth said:

@Brian I have had confirmation that this does work in SharePoint 2010 as well (although I haven't tried).  I think you could use the same technique for E-mail a link.  Although, a bit more work would be involved since you would have to collect the E-mail address to send to.

January 6, 2012 12:59 PM

Robert said:

I am guessing this thread is now dead, but I am trying to get this working in SP2010. I have had it working in SP2007 with no problems. However, I just cant get it to work. Has anyone done so and if so, can you post the differences? It compiles just fine on the SP2010 server, deploys fine via stsadm, I have the proper lines in the results.aspx, but it just wont render anything in the search page. I am stumped, I hope someone is still watching this thread and can help. Thanks!

February 16, 2012 8:22 AM

CoreyRoth said:

@Robert I have had a few people tell me that it works in SharePoint 2010 but I haven't had time to verify it myself.  If it's not showing up I would look carefully at where you are adding the lines to the XSL as that is likely the problem.  Try it in a few spots with just some test text.  Once you find the right spot, you can add the code back in.  For an example of a good spot, see this post.

February 16, 2012 10:28 PM

Robert said:

Thanks for the reply Corey, I will have a look, but I have tried inserting the code in a few different places, and even threw in some standard HTML that rendered just fine so I "think" I have the correct placement. However, I am not sure the conditional test is working as I have seen a number of different ways to do this via XSL on google searches. I will try removing the conditional and see if the URL's render.  Thanks again for the reply, good to see this post is not dead! This really is very handy to have the go to folder when there are multiple associated documents in the same folder.

February 17, 2012 9:10 AM

Robert said:

Corey, the link you provided got the job done. It is working just fine. I was doing 2 things wrong. First, I had my conditional syntax wrong. Second, I was editing the search results web part XSL and not going through the Search Service Application as you suggest in the link provided. All is well and I thank you a MILLION!

February 17, 2012 1:44 PM

CoreyRoth said:

@Robert Excellent.  Glad it is working for you!

February 20, 2012 8:45 PM

Daniel said:

Is it anyway possible to get this for WSS 3.0?  I only need to be able to see the Document Properties

June 4, 2012 2:28 PM

CoreyRoth said:

@Daniel the only supported way to use that snippet with WSS 3.0 is by adding Search Server Express.

June 6, 2012 1:33 PM

subbu said:

Is there a similar solution for adding a "Check In" " Check Out" link in the search results?

September 6, 2012 10:13 AM

CoreyRoth said:

@subbu Not that I know of.  One could possible be developed.

September 6, 2012 10:29 AM

Leave a Comment


About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2015 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems