Jaa


Edit documents directly from the search results page

While using SharePoint 2007, I have come across the following behavior:

- When clicking on a document's name from within the document library, you are prompted to either open it as "Read-only", or in the "Edit mode".
- When searching for the same document, and clicking on it's name from the search results page, you are presented with a completely different dialog (the Internet Explorer standard "Open / Save / Cancel").

So what if you want to have a consistent behavior between the two screens?
A bit of research shows that inside the document library, Internet Explorer launches Word with the following parameters:  /h /n /dde, whereas in the search results page, Word gets launched by the Generic Host Process, without these parameters. The key parameter here is “ /h”, which according to https://support.microsoft.com/kb/210565 implements exactly this functionality.

Therefore I developed my own customization, which could be used in order to achieve a similar functionality from within a Search page. Below are the steps I performed:

1. enable the Office SharePoint Server Publishing Infrastructure under the Site Collection Features
2. enable Office SharePoint Server Publishing under the Site Features
3. create a Search Center sub-site
4. go to Site Settings, Search Settings and enable custom scopes, by using the Search Center created at the previous step
5. edit the Search Core Results web part on the Search Center page
6. make the following substitution in the XSL Editor:

 <span class="srch-Title">
<a href="{$url}" mce_href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">

to

 <script language="JavaScript">
function OpenDoc (elem) {
  DispEx(elem,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3', '0','SharePoint.OpenDocuments','','','','1','0','0','0x7fffffffffffffff');
  return false;
}
function removeUrl (elem) {
  elem.href = window.location;
}
</script>

<span class="srch-Title">
<xsl:variable name="doc">
  <xsl:choose>
    <xsl:when test="contains($url,'.doc')">
      <xsl:value-of select="'javascript:OpenDoc(this)'"/>
    </xsl:when>
  </xsl:choose>
</xsl:variable>
<xsl:variable name="doc2">
  <xsl:choose>
    <xsl:when test="contains($url,'.doc')">
      <xsl:value-of select="'javascript:removeUrl(this)'"/>
    </xsl:when>
  </xsl:choose>
</xsl:variable>
<a onmousedown="{$doc}" onmouseup="{$doc2}" href="{$url}" mce_href="{$url}" id="{concat('CSR_',$id)}" title="{$url}">