Search code examples
asp.netexcelhttpmicrosoft-edgeattachment

Is there a way to force MS Edge to open an Excel file within itself rather than download it?


In my organization, which uses MS Edge as its default browser, there is a regularly updated and frequently opened Excel spreadsheet which we host on an internal IIS server and to which we link from a different internal ASP.NET website, also on IIS. Every time someone clicks the link, the file gets downloaded again and has to be manually opened in the user's desktop copy of Excel even though it's possible for Edge to view MS Office files now (through the Office web app) and this setting is on by default. Whether or not this "Open Office files in the browser" option in Edge is enabled has no bearing on what happens. Dragging and dropping, or Ctrl+O-ing the downloaded file just makes Edge "download" it again.

My questions here:

  • how exactly does Edge decide what MS Office files it can open? Are only certain versions of Office supported? I have tried both the default .xlsx filetype and the Office 97-2003 .xls with the same effect; the file is likely not in any way malformed or peculiar, as my test files were almost empty spreadsheets with one cell of text
  • is there some mechanism to force a browser to try to open a file it supports, something like the opposite of the download attribute on an a tag? Content-Disposition: inline seems like what I'm looking for, but inspecting the download in the network tab shows me that this header isn't present, so inline should be the value assumed by default.
  • I have considered embedding a copy of the document stored in OneDrive, but this feature seems to have been deprecated. Is that the case or is it something that can be disabled by an organization?

As a last resort, we could instead store the document as a PDF (it is essentially read-only).

Tried:

  • forcibly enabling the "Open Office files in the browser" option with a group policy/registry key
  • simply opening the link to the file
  • opening locally stored Excel files with Edge

Everyone is signed into Office 365 with their Microsoft account, which I've also seen mentioned as a requirement.

Expectations:

  • the Excel file is displayed to the user in a new tab using Edge's Office viewer feature

Reality:

  • the Excel file is downloaded

Solution

  • "Open Office files in the browser" this feature works for public reachable Office documents under the below limitations. You can refer to this article and check if your Excel file meets the requirements:

    The OpenInOfficeViewerIfApplicable feature watches navigations to detect when Office-related file extensions (.xls, .docx, pptx, etc) or Content-Types (application/msword, application/vnd.ms-excel, etc) are observed, indicating that a navigation led directly to an Office document that would otherwise be deemed as having a non-webby MIME type and thus normally be converted into a download.

    The feature is bypassed if:

    1. The Open Office files in the browser checkbox is turned off in edge://settings
    2. The response contains a Content-Disposition:attachment header
    3. The request contains an Authorization or Proxy-Authorization header
    4. The user initiated the download from the “Save As” item on the browser’s context menu
    5. The referring URL is on a limited set of exempted domains (Office, SharePoint, OneDrive, Blackboard, etc)
    6. The request method is not GET
    7. The file size is not known (e.g. Transfer-Encoding: chunked)
    8. The file size is over 100mb
    9. The browser is running in Incognito mode
    10. The file was served from an IP address that is not publicly routable