Wednesday, October 21, 2009

Force Browser Enabled Forms to Open in Browser from Sharepoint Search Results Page

This has been a problem I wanted to tackle a while back and finally got around to it. The basic problem is that selecting an infopath Form from the MOSS Search Results Page will result in a prompt to download the Form or open it in the InfoPath Thick Client if it is installed. My client wants the Browser-Enabled forms to ALWAYS open in the Browser.

The Web Part of interest is on the Results.aspx (or a custom Search Results page if you have one) and is titled 'Search Core Results'. Edit the Results.aspx page and then edit the Search Core Results Web Part - Modify Shared Web Part. Navigate to the XSL Editor under Data view Properties and open up the XSL editor window. The line we are interested in changing is the one setting the url variable:

We basically want to change this variable to reflect the url that is needed to render the Form by the forms server. To do this we need to first add the formserver url followed by '/_layouts/FormServer.aspx?XmlLocation=' followed by the url to the form followed by &DefaultItemOpen=1. If it is not a form we want to set the url as normal.


Replacing the <xsl:variable name="url" select="url"/> line with the following xsl performs this:
<xsl:variable name="url">
<xsl:choose>
<xsl:when test="contentclass='STS_ListItem_XMLForm'">
<xsl:value-of select="sitename"/>
<xsl:text>/_layouts/FormServer.aspx?XmlLocation=</xsl:text>
<xsl:value-of select="url"/>
<xsl:text>&DefaultItemOpen=1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="url"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>



Note: If you use the "Search this Site" or "Search this List" scopes you will be directed the WSS (NOT Search Center) results page and this fix will not work. You will need to redirect the OSSSEARCHRESULTS.aspx page to to Search Center Results page. Several BLOG posts are available to do this and it involves a small JavaScript addition to the OSSSEARCHRESULTS.aspx.

Since this is a page that may be modified in the future by Service Packs you may want to package this up in a solution so post service pack remediation will not be necessary.

1 comment:

  1. If you copy the xsl from this post be sure to replace the & with & in the &DefaultItemOpen=1 line.

    Otherwise your xsl will not work and Sharepoint will give you an error.

    ReplyDelete