in

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

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2012.

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
 

Sunny said:

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

September 10, 2010 12:15 PM
 

CoreyRoth said:

@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>

September 10, 2010 12:29 PM
 

David said:

This is great. Thanks.

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

November 16, 2010 9:02 AM
 

Darren said:

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

December 14, 2010 11:32 AM
 

CoreyRoth said:

@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.

December 16, 2010 10:48 AM
 

Anpassa s??ktr??ffen med Visual Studios XSLT-debugging « Sharepointkaos said:

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

April 13, 2011 3:22 PM
 

edit SharePoint Search Result with Visual Studio xslt-debugging « Sharepointkaos said:

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

April 13, 2011 3:37 PM
 

Petr said:

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

July 18, 2011 10:08 AM
 

CoreyRoth said:

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

July 20, 2011 9:07 AM
 

Gigi said:

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

July 28, 2011 11:22 AM
 

Geoff said:

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

July 29, 2011 6:22 AM
 

CoreyRoth said:

@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.

August 4, 2011 9:07 AM
 

kevin d said:

"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....

August 29, 2011 12:34 PM
 

kevin dube said:

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>

August 29, 2011 7:28 PM
 

chhaya said:

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...

September 15, 2011 3:08 AM
 

Keyur Patel said:

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

September 15, 2011 3:13 AM
 

CoreyRoth said:

@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.

September 15, 2011 5:28 PM
 

Open Document with the DispEx function in Sharepoint | spindia said:

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

September 17, 2011 1:16 AM
 

Markus said:

Is there a description of the DispEx parameters?

December 14, 2011 8:21 AM
 

CoreyRoth said:

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

January 5, 2012 4:02 PM
 

Paul Jones said:

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.

February 17, 2012 4:01 AM
 

CoreyRoth said:

@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.

February 20, 2012 8:49 PM
 

Greg U said:

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

May 9, 2012 2:03 PM
 

TIna Scott said:

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

May 18, 2012 6:19 PM
 

CoreyRoth said:

May 29, 2012 9:55 PM
 

CoreyRoth said:

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

May 29, 2012 10:00 PM
 

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

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

August 10, 2012 5:39 AM
 

subbu said:

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

September 6, 2012 10:09 AM
 

CoreyRoth said:

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

September 6, 2012 10:30 AM
 

Vlad said:

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.

September 10, 2012 8:26 AM
 

CoreyRoth said:

@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.

September 10, 2012 8:31 AM
 

Michael said:

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.

September 18, 2012 8:20 AM
 

CoreyRoth said:

@Michael be sure and uncheck use location visualization first.

September 18, 2012 1:50 PM
 

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

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

February 22, 2013 7:30 AM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an Applications Architect at Infusion specializing in ECM and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems