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

5 בינואר 2009

תגיות: , , , ,
4 תגובות

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

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

4 תגובות

  1. Gerwin van Ee16 בפברואר 2009 ב 16:05

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

    להגיב
  2. Tom Vervoort9 במרץ 2009 ב 14:05

    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.

    להגיב
  3. Salahuddin Belal25 במרץ 2009 ב 0:41

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

    להגיב
  4. Tekraj3 באוגוסט 2009 ב 14:29

    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= להגיב