in

Dot Net Mafia

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

This Blog

Syndication

Corey Roth - DotNetMafia.com - Tip of the Day

Bringing you the latest time saving tips for SharePoint 2010, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2010

Adding an Edit Document Link to Enterprise Search Results

I have seen a lot of requests to get more functionality on search results for documents lately.  People want to be able to edit documents, go to the folder the document is in, go to the site, view properties, etc.  I have solutions for all of those which I will be sharing in the next few days.  However, I wanted to share this one first, because it is easy to implement and does not require any custom code.  The goal is to get a link that will allow you to edit the document (instead of opening it in read only mode) directly from your search results. 

As you will see the solution is actually quite simple.  Start by editing your results.aspx page and then edit the CoreResultsWebPart.  I have chosen to put my Edit Document link on the line following the title of the document.  In the Data View Properties of the web part, click XSL Editor.  Scroll down and look for the span with a class of srch-Title and insert the following block of code after the closing span and before the srch-Description.

    <div class="srch-Description">

        <a href="{$url}" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','0

','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff')">Edit Document</a>

    </div>

Save the XSL and click Apply.  You should now see an Edit Document link in your search results similar to the one below.

SearchResultsEditDocumentLink

Clicking on the Edit Document link will present the user with the Read Only / Edit menu just like they get when they are opening the document from a document library.

SearchResultsEditDialog

How did I figure this magic out?  It really was pretty simple, I just looked at a document library page and figured out what script method was being called.  If you spent money on a high dollar product just to get this feature, I am sorry.  Also remember that the Edit Document functionality only works in Internet Explorer.  Try it out and see if it works for you.  For other document functions such as Go to Folder, View Properties, and View Version History, take a look at my Document Link Handler for Enterprise Search.

Comments

 

marcus said:

Hi Corey,

I have just tried this solution and it does work however, if you have a managed document library with versioning enabled and the checkout/check in options it bypasses this allowing you to edit the document without the version number changing?

Maybe I am doing something wrong but this is how it appeared on my first attempt.

October 28, 2008 2:45 AM
 

CoreyRoth said:

I just did a few tests and it did update the version number for me.  I tried it with having major versioning enabled.  I also tried it with and without checkins required.  I was testing a Word 2007 document in this case.  What kind of document were you trying it with?  Thanks.

October 30, 2008 10:16 AM
 

GrandmasterPhil said:

Hi Corey,

I implemented your code, but unfortunately the document opens exactly the same without the Edit/Read option.  

In my code there is a <xl:choose> tag right after the close of the Title span; is this correct?

-GrandmasterPhil

November 4, 2008 4:39 PM
 

CoreyRoth said:

After I posted I realized, I was not clear enough on the location it needs to go in.  There are actually two srch-Title spans.  The first one is used when there are no search results.  Put it after the second one.  Thanks.

November 10, 2008 10:47 AM
 

lester_sdu said:

Hi Corey,

But i can only found one srch-Title span. So where is the correct location to add in that bit of code?

Thank you!

November 18, 2008 1:00 AM
 

CoreyRoth said:

Sorry, I was thinking of the srch-Description span.  Yes, there is only one srch-Title tag.  I usually put my link between the span and the xsl:choose that you mentioned.  

Also keep in mind the code I am adding adds a link to edit the document it doesn't change the default action of clicking on the title of the document.  If you want that action, you could add the onclick event from the code provided above on that link.

November 20, 2008 9:10 AM
 

lester_sdu said:

Hi Corey,

Thanks for that, so far all working good with office 2007.

but is your code work with Office 2003? Because in our organisation some of the machine still using office 2003 and It seems not not working well with it. It doesn't give you the read only or Edit option when you click on 'edit document'.

Thanks!

November 20, 2008 6:58 PM
 

CoreyRoth said:

That is a good point.  I think the script for working with Office 2003 is a bit different.  I'll need to look around and see if I can find a machine to try it on.  Everything I have access to has been upgraded.

November 24, 2008 3:18 PM
 

David Birin's blog said:

I visited a customer which wanted the option to directly open a document from the search results for

January 5, 2009 3:47 AM
 

keith said:

Hi Corey

Just what I needed, however, did you manage to find the code for Offfice 2003?

Cheers

May 15, 2009 4:11 AM
 

CoreyRoth said:

Keith, someone provided me some JavaScript for that, but I can't seem to find it right now.  I'll keep looking.

May 19, 2009 3:06 PM
 

johns said:

Hi all,

I added the code:

<div class="srch-Description">

       <a href="{$url}" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','0

','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff')">Edit Document</a>

   </div>

to my results.aspx. The "Edit Document" link became visible, but when I clicked the "Edit Document" exactly the same happened as before.

What do I have to do with the "CoreResultsWebPart".

Thanks in advance.

Greetings,

John

July 22, 2009 2:29 PM
 

CoreyRoth said:

John,

What version of Office are you using?  I've discovered that snippet only works with 2007.

Thanks,

Corey

August 14, 2009 8:42 AM
 

johns said:

Hi Corey,

I use MS office 2007. The extension of the most files on the SP server are doc file. This weekend I uploaded some docx files and started a full crawl. Unfortunately it didn’t work. I see a popup which asked to save or open the file. I only added the code you provided to the “core results” webpart, which displayed the edit text in the search results.

Any other ideas?

Thanks in advance

Greetings,

John

August 18, 2009 7:16 AM
 

CoreyRoth said:

Hmmm, that is interesting.  The JavaScript there is effectively just the same JavaScript that is used in the context menu when you edit a document in a document library (which I assume works fine for you).  Let me dig a little and see if I can find anything else.

August 18, 2009 10:12 AM
 

Somesh said:

Dear All,

I really appriciate the effort of CoreyRoth. I face same problem as you all. I made little chnage in the script and it is now working on version office 2007 as wel as on version office 2003.

<div class="srch-Description">

<a onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','','0','SharePoint.OpenDocuments','','1','','1','0','0','0x7fffffffffffffff')" onfocus="OnLink(this)" href="{$url}">Edit Document</a>

   </div>

August 2, 2010 1:52 AM
 

CoreyRoth said:

@Somesh.  Thanks for the update on the script to work in Office 2003;

August 2, 2010 9:27 AM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is a SharePoint Consultant for Stonebridge, Inc. specializing in clients in the Energy Sector.
2009 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems