Adding an Edit Document Link to Enterprise Search Results

Posted Monday, October 27, 2008 5:18 PM by CoreyRoth

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

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, October 28, 2008 2:45 AM by marcus

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.

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, October 30, 2008 10:16 AM by CoreyRoth

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.

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, November 4, 2008 4:39 PM by GrandmasterPhil

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

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, November 10, 2008 10:47 AM by CoreyRoth

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.

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, November 18, 2008 1:00 AM by lester_sdu

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!

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, November 20, 2008 9:10 AM by CoreyRoth

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.

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, November 20, 2008 6:58 PM by lester_sdu

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!

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, November 24, 2008 3:18 PM by CoreyRoth

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.

# MOSS – Open search results for editing (Office 2003/7)

Monday, January 5, 2009 3:47 AM by David Birin's blog

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

# re: Adding an Edit Document Link to Enterprise Search Results

Friday, May 15, 2009 4:11 AM by keith

Hi Corey

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

Cheers

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, May 19, 2009 3:06 PM by CoreyRoth

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

# re: Adding an Edit Document Link to Enterprise Search Results

Wednesday, July 22, 2009 2:29 PM by johns

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

# re: Adding an Edit Document Link to Enterprise Search Results

Friday, August 14, 2009 8:42 AM by CoreyRoth

John,

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

Thanks,

Corey

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, August 18, 2009 7:16 AM by johns

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

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, August 18, 2009 10:12 AM by CoreyRoth

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.

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, August 2, 2010 1:52 AM by Somesh

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>

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, August 2, 2010 9:27 AM by CoreyRoth

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

# re: Adding an Edit Document Link to Enterprise Search Results

Friday, September 10, 2010 12:15 PM by Sunny

This works great for documents but for other items in search results like site or apge is also opening edit mode. Is there way to avoid edit option for site and pages in search results

# re: Adding an Edit Document Link to Enterprise Search Results

Friday, September 10, 2010 12:29 PM by CoreyRoth

@Sunny Sure.  You can add a check to verify that the file is a document, just put your link inside an xsl:if like this.

<xsl:if test='isdocument = 1'>

</xsl:if>

That is the syntax for SharePoint 2007.  If you are using SharePoint 2010, you would use:

<xsl:if test="isdocument = 'True'">

</xsl:if>

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, November 16, 2010 9:02 AM by David

This is great. Thanks.

I can not beleive Microsoft haven't fixed this in SharePoint 2010.

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, December 14, 2010 11:32 AM by Darren

Can someone post a version of this for SharePoint 2010.  It will be greatly appreciated.

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, December 16, 2010 10:48 AM by CoreyRoth

@David Have you tried it with 2010 yet?  I'm not sure how much the JavaScript has changed or not so I am curious.  If it doesn't work, I'll start seeing if I can find a solution.

# Anpassa s??ktr??ffen med Visual Studios XSLT-debugging &laquo; Sharepointkaos

Pingback from  Anpassa s??ktr??ffen med Visual Studios XSLT-debugging &laquo; Sharepointkaos

# edit SharePoint Search Result with Visual Studio xslt-debugging &laquo; Sharepointkaos

Pingback from  edit SharePoint Search Result with Visual Studio xslt-debugging &laquo; Sharepointkaos

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, July 18, 2011 10:08 AM by Petr

Tried this code (with the xsl document test) on Sharepoint 2010 and works nice! Thanks!

# re: Adding an Edit Document Link to Enterprise Search Results

Wednesday, July 20, 2011 9:07 AM by CoreyRoth

@Petr Excellent!  Glad to know it works on 2010 as well.  Thanks for trying it out.

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, July 28, 2011 11:22 AM by Gigi

Hi Corey,

your solution worked for me but I have a machine in the Farm in which it doesn't work.

I noticed that also when I try to edit a document from document Library it doesn't work. The window ReadOnly/Edit mode doesn't appear, SP opens the doc in read-only mode.

Any Idea?

Thanks for your support

# re: Adding an Edit Document Link to Enterprise Search Results

Friday, July 29, 2011 6:22 AM by Geoff

Can an argument to the javascript be changed so that the document opens up without the dialog asking "Read-only" or "Edit"?

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, August 4, 2011 9:07 AM by CoreyRoth

@Geoff I think it's possible but I think it depends on your version of SharePoint and Office to make it actually happen.  I'd have to dig more into it.

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, August 29, 2011 12:34 PM by kevin d

"i'm trying to use this and it is launching a dialog "What do you want to do with xxx.docx" with options Open (this file won't be saved automatically), Save or Save as.  Is this a problem with IE9 or Sharepoint 2010?  I can't get the edit dialog to come up.  When you click open on the dialog i mentioned above it opens the doc read only which is no good....

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, August 29, 2011 7:28 PM by kevin dube

you can ignore my previous comment, here is my revised working version, filtering out pdfs (which you can't edit anyways) and files that reside on the file share (start with servername rather than http) our search crawls file share and sharepoint, the edit link doesn't work for file share type files

<xsl:if test="not(contains($url,'.pdf'))">

<xsl:if test="contains($url,'http')">

<xsl:if test="isdocument = 'True'">

<div class="srch-Description">

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

   </div>

</xsl:if>

</xsl:if>

</xsl:if>

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, September 15, 2011 3:08 AM by chhaya

if the current user has permission on document item level then only i have to open document in edit mode..or edit link should be visible..then what should do...plz guide...

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, September 15, 2011 3:13 AM by Keyur Patel

Hello Corey, It's great solution, but I want this funtionallity with "Check User Permission".

Means, If current logged in user has Edit permission on that perticular document then only "Edit Document" link appear. Other wise not.

Thanks in advance

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, September 15, 2011 5:28 PM by CoreyRoth

@Keyur I would push back on that requirement as it will not easily be achieved.  In order to accomplish that, you would have to make a call to the API for every result returned and see if the user has edit permission or not.  This would be hard to implement, require heavy use of the client API and would not likely perform well.

# Open Document with the DispEx function in Sharepoint | spindia

Saturday, September 17, 2011 1:16 AM by Open Document with the DispEx function in Sharepoint | spindia

Pingback from  Open Document with the DispEx function in Sharepoint | spindia

# re: Adding an Edit Document Link to Enterprise Search Results

Wednesday, December 14, 2011 8:21 AM by Markus

Is there a description of the DispEx parameters?

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, January 5, 2012 4:02 PM by CoreyRoth

@Markus I don't know that there is.  I discovered the use of it simply by inspecting a page.

# re: Adding an Edit Document Link to Enterprise Search Results

Friday, February 17, 2012 4:01 AM by Paul Jones

Hi,

Can yuou please tell me where do I find the results.aspx page? I';m using sharepoint designer 2010 (and sharepoint 2010) and simply can not find the page to edit.

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, February 20, 2012 8:49 PM by CoreyRoth

@PaulJones you will find the results.aspx page in your search center.  If you do not have a search center yet you can create one from the new site menu.

# re: Adding an Edit Document Link to Enterprise Search Results

Wednesday, May 9, 2012 2:03 PM by Greg U

Is there a similar solution for adding a "View Properties" or Edit Properties" link in the search results?

# re: Adding an Edit Document Link to Enterprise Search Results

Friday, May 18, 2012 6:19 PM by TIna Scott

Can you tell me what we would need to adjust within the  - return DispEx(event.srcElement,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','0','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff'); to open in Multi-edit Mode and not to lock others out of the file

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, May 29, 2012 9:55 PM by CoreyRoth

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, May 29, 2012 10:00 PM by CoreyRoth

@Tina I'm not sure off hand.  If I figure it out, I'll post here.

# Sharepoint: Datei direkt per Klick im Edit-Modus ??ffnen | nodomain.cc

Pingback from  Sharepoint: Datei direkt per Klick im Edit-Modus ??ffnen | nodomain.cc

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, September 6, 2012 10:09 AM by subbu

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

# re: Adding an Edit Document Link to Enterprise Search Results

Thursday, September 6, 2012 10:30 AM by CoreyRoth

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

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, September 10, 2012 8:26 AM by Vlad

Is it possible to hide Edit link for users that only have read permissions for document? It's confusing if they click on Edit but it opens as Read Only because of security.

# re: Adding an Edit Document Link to Enterprise Search Results

Monday, September 10, 2012 8:31 AM by CoreyRoth

@Vlad good question.  That would require a heap of code to make work and it wouldn't be very efficient since you would have to write something to check if the user has permissions or not for each result.

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, September 18, 2012 8:20 AM by Michael

Corey, I am unable to edit the web part as the XSL editor is grayed out.    Where via SP2010 Designer would I add your snippet?

I am not a developer (an infrastructure guy) who has to dabble in SP.... many thanks.

# re: Adding an Edit Document Link to Enterprise Search Results

Tuesday, September 18, 2012 1:50 PM by CoreyRoth

@Michael be sure and uncheck use location visualization first.

# Do you want to be able to edit documents directly from the SharePoint Search Result? | @Deladet

Pingback from  Do you want to be able to edit documents directly from the SharePoint Search Result? | @Deladet

Leave a Comment

(required) 
(required) 
(optional)
(required)