Link to “open in browser” with Office Web Apps




In SharePoint 2013, especially when on Office 365, you probably want to take advantage of Office Web Apps (OWA) to open Office documents (Word, Excel, PowerPoint, etc) in the browser.

EDIT: In SharePoint Online the best way to achieve this is by adding ‘web=1’ as a query string parameter to the file URL. E.g. https://tenant.sharepoint.com/Documents/file.docx?web=1

URL to 'Open in brower'
URL to ‘Open in brower’

A common scenario could be an implementation of the “Feedback (SharePoint 2010)” workflow which creates a task with accompanying email for many users. Some of these users may not be able to open Office documents on their client. Unfortunately, the default email content provides a link which only allows the user to download the document (which they are then unable to view) and provides no link back to the document library to find the document in a more manual fashion. In this particular scenario SharePoint Designer (SPD) is a very useful tool to update the email content with a link that allows users to take advantage of OWA. I am not going to go into how to update the workflow using SPD, I will only discuss the link URL format itself.

The URL format you are looking for is: <Site URL>/_layouts/15/WopiFrame.aspx?sourcedoc=<Doc URL>&action=default

Some things of note:

  • If you inspect the href of a document in a library you will notice that the sourcedoc parameter is not a URL but GUID. This GUID is NOT the unique ID of the document. Providing the unique ID of the document instead of the URL will fail (or potentially display another document).
  • You can provide either an absolute URL or a server relative URL for the source doc, and ensure it is encoded.

In case you are using SPD the link address you want is:
[%Workflow Context:Current Site URL%]/_layouts/15/WopiFrame.aspx?sourcedoc=[%Current Item:Encoded Absolute URL%]&action=default
 

EDIT 31/30/2015: I’ve been advised by a colleague that this only works when the Site URL and Doc URL are both relative to the same site. This appears to be true in SharePoint Online, however I am almost certain this was not an issue when I wrote this article (I no longer have access to that environment).

Paul.




25 thoughts on “Link to “open in browser” with Office Web Apps”

    1. To be honest I am not exactly sure how it works in SP2010 (and I don’t have an SP2010 environment with OWA to test it out) but if it doesn’t work exactly like it does for SP2013, you can discover the link format that SharePoint uses by finding a link that opens a document in OWA and inspecting the href.
      If it is different, please post your findings here!

  1. Hi Paul,
    Replacing that GUID by the document Encoded relative URL or Server encoded URL does not work for me. I am working in SharePoint online. Any idea how to extract this GUID from the existing file?
    Thanks

  2. Thanks for this – worked a treat. For anyone else in Paul’s situation, using the relative url works fine in SP online.
    eg.
    /_layouts/15/WopiFrame.aspx?sourcedoc=/path/to/document/document.doc&action=default

    Cheers,

  3. Hi, would you know how to pass credentials with it? My goal is basically not to require another log-in on the part of the user accessing the link. I’m using CSOM already with credentials and I’d like to use those credentials to automatically log-in for the WopiFrame view. Would you know if this is at all possible? Thanks!

  4. Hi. I would like to know if it’s possible, in any way, to provide/render a preview for a non-public Sharepoint document using the WOPIFrame but without asking the user for log-in details. I’m using CSOM to access the document library. I already have details of the files so I could construct the link. Problem is, clicking the link would ask for log-in details. I would like to use the credentials I’ve been using to directly access the library. Any thoughts would be appreciated. Thanks!

    1. I’m not sure that I am completely following you. The user which wants to render the document in their browser (using the WOPI frame) will need to have access to the source document. It doesn’t need to be anonymously accessible, but in the case which it is not, the user will have to log in.

  5. Many thanks for your post.

    Just because I have had throuble to determine the path to the document I am posting what worked for me

    https://{site}-my.sharepoint.com/personal/{user_domain_com}/_layouts/15/WopiFrame.aspx?sourcedoc=%2Fpersonal%2F{user_domain_com}%2FDocuments%2F{path to document}&action=default

    {path to document} =

    folderX%2FDocument%2Edocx – The document Document.docx is located in the Documents\folderX folder

    Document%2Edocx – The document Document.docx is located in the Documents folder

  6. Does this apply to hyperlinks on a sharepoint page as well? If I open a document from the library it resides in, it will open with office web apps. If I open it from a link on a page within the same site, it opens in the client. If I change the link to the document using the format described above, it works great. But that can’t be the way.

    1. Same issue. I am trying to find a simple way to ensure that document links posted in List records and such will respect the OWA settings rather than ALWAYS open in the client/desktop office tool.

  7. For SPS2010 users who want to add link in SPD2010 email hyperlink, open a document you have on the list you are making the workflow on, copy the URL of the OWA, and paste the URL into your hyperlink in your workflow. Replace the URL in between the .aspx?id= and &Source like below.

    http://yoursite.com/_layouts/WordViewer.aspx?id=%5B%Current Item:Server Relative URL%]&Source=http%somethingsomethingaspx&DefaultItemOpen=1

    1. @Paul / @chamil

      Yep I have been inserted the link in both SPD email alerts and Nintex Workflow for Office 365 Assign tasks -> Initial emails and so far no issues I had been trying to decipher Get-SPOListItem and REST calls until I hit upon this blog post. Thanks again.

  8. Thanks….
    Below URL format works.
    The URL format you are looking for is: /_layouts/15/WopiFrame.aspx?sourcedoc=&action=default

  9. action=default or action embedview, does not hide the status bar.
    Status bar contains the full screen option, I want to hide that option any idea how that can be done?

Leave a Reply

Your email address will not be published.