DCSIMG
MOSS – Open search results for editing (Office 2003/7) - David Birin's blog

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

I visited a customer which wanted the option to directly open a document from the search results for editing (in default when you click a document from the search results it opens as read-only). I found this blog article which describes how to do it by embedding some JavaScript into the search results XSL, I did exactly as described and it didn’t work, I realized that this happens because this customer uses Office 2003. I had to do some digging using the IE developer toolbar (soon to be an integral part of IE8) on the “Edit with Microsoft Word” context menu item, which brought me to the conclusion to use other JavaScript functions to open files as described bellow:

<div class="srch-Description">
    <a href="{$url}" onclick="return editDocumentWithProgID2('{$url}','','SharePoint.OpenDocuments')">Edit Document</a>
</div>

To use this, edit you results XSL, insert this code before the srch-Description span (in the “main body template” area – this span appears few more times in the XSL).

After adding it your search result should look like this:
 image

This code was tested and working both with Office 2003 and Office 2007.

I did some more editing on the XSL in order to display the “Edit Document” link only for office documents.

The version which supports 2003 documents (.doc, .xls, .ppt)

<xsl:if test="substring($url,string-length(normalize-space($url))-3,4) = '.doc'
or substring($url,string-length(normalize-space($url))-3,4) = '.xls'
or substring($url,string-length(normalize-space($url))-3,4) = '.ppt'">
 
<div class="srch-Description">
        <a href="{$url}" onclick="return editDocumentWithProgID2('{$url}','','SharePoint.OpenDocuments')">Edit Document</a>
    </div>
</xsl:if>

The version which supports 2003 & 2007 documents (.doc, .xls, .ppt, .docx, .xlsx, .pptx)

<xsl:if test="substring($url,string-length(normalize-space($url))-3,4) = '.doc'
or substring($url,string-length(normalize-space($url))-3,4) = '.xls'
or substring($url,string-length(normalize-space($url))-3,4) = '.ppt'
or substring($url,string-length(normalize-space($url))-4,5) = '.docx'
or substring($url,string-length(normalize-space($url))-4,5) = '.pptx'
or substring($url,string-length(normalize-space($url))-4,5) = '.xlsx'">
 
<div class="srch-Description">
        <a href="{$url}" onclick="return editDocumentWithProgID2('{$url}','','SharePoint.OpenDocuments')">Edit Document</a>
    </div>
</xsl:if>

David Birin

Published 05 January 2009 11:47 AM by DavidBi

Comments

# Gerwin van Ee said on 16 February, 2009 04:05 PM

When i use your script, the word document  is opened twice. Once as Read only and once in Edit mode. What do i do wrong???

# Tom Vervoort said on 09 March, 2009 02:05 PM

It's because both the link is opened and the javascript is executed. Replace the onclick="return editDocumentWithProgID2('{$url}','','SharePoint.OpenDocuments')" with onclick="editDocumentWithProgID2('{$url}','','SharePoint.OpenDocuments'); return false;". This prevents the link from opening (in read-only mode) after the javascript has executed.

# Salahuddin Belal said on 25 March, 2009 12:41 AM

Adding return false at the end of the onclick section did not seem to help...

# Tekraj said on 03 August, 2009 02:29 PM

Hi David

would it be possible to get the document library location (omitting the folder names) from the $url so that we users can directly go to properties of the document?

Forms/DispForm.aspx?ID=<listid>

Leave a Comment

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

Enter the numbers above: