SharePoint 2013 CQWP Office Online hyperlink

With the introduction of Office Online (Office web apps) files can be opened in the browser with Office Online (Office web apps) or with the local client. If able SharePoint 2013 will open files (.pptx, docx, xslx) in office Online and other files in the related client (doc, xsl, pdf etc.) This behavior works great within the document library, however this does not work out of the box for files that are displayed using a content query webpart. With XSLT we are able to create an variable which creates per file the required hyperlink.

Solution
1. Edit the CQWP Template where the semi dynamic hyperlink is required.
2. First we need to create the variable that builds the correct office online or default hyperlink. The default hyperlink opens the files in the client software.

<xsl:variable name="DynamicURL">
   <xsl:choose>						
      <xsl:when test="contains(@FileExtension,'docx')">
         /sites/PH/OH/_layouts/WopiFrame.aspx?sourcedoc=<xsl:value-of select="@LinkUrl"/>	
      </xsl:when>
      <xsl:when test="contains(@FileExtension,'pptx ')">
         /sites/PH/OH/_layouts/WopiFrame.aspx?sourcedoc=<xsl:value-of select="@LinkUrl"/>	
      </xsl:when>
      <xsl:when test="contains(@FileExtension,'xslx')">
         /sites/PH/OH/_layouts/WopiFrame.aspx?sourcedoc=<xsl:value-of select="@LinkUrl"/>	
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="@LinkUrl"/>
      </xsl:otherwise>
   </xsl:choose>
</xsl:variable>

3. The choose function determines the file type and sets the correct Office Online hyperlink or the default Hyperlink based of LinkUrl field.
4. Secondly we need to use the DynamicURL variable to create the hyperlink.

<a href="{$DynamicURL}" target="_blank">
   <xsl:value-of select="@Name"/>
</a>

 

Result
Files with extensions docx, pptx and xslx will open in Office Online other files will open in the related client.

CQWP Hyperlink Office Online

Share

7 Replies to “SharePoint 2013 CQWP Office Online hyperlink”

  1. Thanks a lot Ben! Great solution…I just have one issue I’m running into: Everything appears to be working as expected, but the URL being returned after “sourcedoc=” is not server-relative which throws an error.

    Any ideas on how to get the server-relative URL to come through?

    Thanks!

  2. Scratch that last comment. @FileRef didn’t work for queries that cross sites. I ended up using the function subsrtring-after and grabbing only a part of the @LinkUrl value

    Thanks again!

  3. Sorry for all the comments..I was implementing this and noticed that Office Web Apps URL’s must contain the site collection and site before /_layouts/wopiframe.aspx. I found a different way of forcing Office Web Apps without hardcoding the URL:
    ?web=1

Leave a Reply

Your email address will not be published. Required fields are marked *