Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

This seems like it should be an easy thing, but it's not working the way I expect it to. I have a SharePoint 2010 site with a document library that contains several Word documents. Office web apps are installed, and the default setting for the farm is to open Word documents in the browser.

When I click on a document link in the AllItems.aspx list view, it does open in the browser (as desired). However, if I click on the same document in a CQWP on a different page, it always prompts me to download the document. How can I force the CQWP to open Word documents in the browser?

share|improve this question
    
There's a duplicate question here: sharepoint.stackexchange.com/questions/12532/… but it has a non-answer to this problem. –  RJ Cuthbertson Oct 31 '12 at 13:30
add comment

2 Answers

up vote 1 down vote accepted

Apparently this is a known issue.

I've got two possible solutions for you.

1) Enable the "Open documents in client applications by default" site collection feature (from MSDN):

http://social.msdn.microsoft.com/Forums/en/sharepointgeneralprevious/thread/90d251c3-43d4-4b05-b87c-7c25bb32a782

2) Modify the XSL to open the document in a new browser window (from the SharePoint Developer Team blog):

http://blogs.technet.com/b/sharepointdevelopersupport/archive/2012/07/24/how-to-open-content-query-web-part-links-in-a-new-ie-window.aspx

share|improve this answer
    
Nice links, I had not come across those. Unfortunately, it seems that both of these suggestions still result in the document opening up in the Office client application. We have some workstations that need to view the documents, but do not have the Office client applications installed. –  jason.venema Oct 31 '12 at 15:35
    
So, the other thing to try here is to use the XSL to alter the link to the document. If you look at the URL in the CQWP as opposed to the URL from the list you will notice they are different. If you can recreate the same URL from the list in the CQWP then it should open the document in the browser. –  RJ Cuthbertson Oct 31 '12 at 16:16
    
That is actually exactly what I ended up doing. The URL is a little hairy looking, but it seems to work (at least for Word documents, which was my requirement). –  jason.venema Nov 2 '12 at 18:37
add comment

For those wondering exactly what I did, I had to edit the ItemStyle.xsl file in the Style Library of my site. In the xsl template for this particular instance of the CQWP, I created a variable called $SiteUrl (I'm not entirely sure I needed to do this, as I am relatively new to this stuff):

<xsl:variable name="SiteUrl">
  <xsl:value-of select="substring-before($SafeLinkUrl,'/Lists/')"/>
</xsl:variable>

Then I leveraged that variable inside of the anchor tag like so:

<div style="position:relative; float:left; padding-right:10px;">
  <a onfocus="OnLink(this)" href="{$SafeLinkUrl}" onmousedown="return VerifyHref(this,event,'1','SharePoint.OpenDocuments','1{$SiteUrl}/_layouts/WordViewer.aspx?id={$SafeLinkUrl}')" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','1','SharePoint.OpenDocuments','','1{$SiteUrl}/_layouts/WordViewer.aspx?id={$SafeLinkUrl}','','1','0','0','0x7fffffffffffffff','','')" target="{$LinkTarget}" title="{@LinkToolTip}" class="CQWPHeader" >
    <xsl:if test="$ItemsHaveStreams = 'True'">
      <xsl:attribute name="onclick">
        <xsl:value-of select="@OnClickForWebRendering"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test="$ItemsHaveStreams != 'True' and @OpenInNewWindow = 'True'">
      <xsl:attribute name="onclick">
        <xsl:value-of disable-output-escaping="yes" select="$OnClickTargetAttribute"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:value-of select="$DisplayTitle"/>
  </a>
</div>

This did the trick for me. If necessary, I suppose I could have used an to look at the file extension and open the Excel viewer for .xls/x files, but that wasn't required for my project.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.