locked
How to get Office Web Access URL to a document? RRS feed

  • Question

  • Hi,

    I'm creating a custom web part that will renders links to certain documents. I want to programatically create links to the correct Office Web Applications viewer (Word, PowerPoint, Excel, etc) based on a documents URL.

    Can this be done with server side code?  Of course I can create a helper class that does this manually, but I guess such as method might already exist in the SharePoint API?

    Thanks,
    Christoffer

    Monday, April 18, 2011 8:30 AM

All replies

  • Hi Christoffer1,

    SharePoint open a document by using the ActiveX control, you can find detail at here: http://msdn.microsoft.com/en-us/library/ms454230.aspx

    You can use DispEx javascript function also, this post will help you:

    http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/db44c515-7eea-431d-8190-2ca848456586/

    Monday, April 18, 2011 8:39 AM
  • Hi ThinkBox,

    Are you sure that the DispEx method actually returns the OWA url for you?

    It doesnt work here. If you look at the HTML source of a document library where OWA is activated, the following method is actually called when clicking on the document is this:

    <a onfocus="OnLink(this)" href="[filename]" onmousedown="return VerifyHref(this,event,'1','SharePoint.OpenDocuments','1http://localhost/_layouts/WordViewer.aspx?id=/Documents/sdfsdfsdf.docx')" onclick="return DispEx(this,event,'TRUE','FALSE','FALSE','SharePoint.OpenDocuments.3','1','SharePoint.OpenDocuments','','1http://localhost/_layouts/WordViewer.aspx?id=[filename]','','1','0','0','0x7fffffffffffffff','','')">sdfsdfsdf</a>

    As you can see, you actually need to provide the URL to WordViewer.aspx in the link. It's this that I need to render on the server side (and the equivalent for powerpoint, onenote and excel viewer), based on the list item URL.

    /Christoffer


    Tuesday, April 19, 2011 2:35 PM