[html] How to open an external file from HTML

I want a list of hyperlinks on a basic html page, which point to files on our corporate intranet.

When a user clicks the link, I want the file to open. They are excel spreadsheets, and this is an intranet environment, so I can count on everyone having Excel installed.

I've tried two things:

  1. The obvious and simple thing:
<a href="file://server/directory/file.xlsx">Click me!</a>
  1. A option that I found in a Google search:
<HTML>
<HEAD>
    <SCRIPT LANGUAGE=VBScript>
    Dim objExcel

    Sub Btn1_onclick()
    call OpenWorkbook("\\server\directory\file.xlsx")
    End Sub

    Sub OpenWorkbook(strLocation)

    Set objExcel = CreateObject("Excel.Application")
    objExcel.Visible = true
    objExcel.Workbooks.Open strLocation
    objExcel.UserControl = true
    End Sub

    </SCRIPT>
    <TITLE>Launch Excel</Title>
</HEAD>
<BODY>
    <INPUT TYPE=BUTTON NAME=Btn1 VALUE="Open Excel File">
</BODY>
</HTML> 

I know this is a very basic question, but I would appreciate any help I can get.

Edit: Any suggestions that work in both IE and Firefox?

This question is related to html

The answer is


If your web server is IIS, you need to make sure that the new Office 2007 (I see the xlsx suffix) mime types are added to the list of mime types in IIS, otherwise it will refuse to serve the unknown file type.

Here's one link to tell you how:

Configuring IIS 6 for Office 2007


A simple link to the file is the obvious solution here. You just have to make shure that the link is valid and that it really points to a file ...


<a href="file://server/directory/file.xlsx" target="_blank"> if I remember correctly.


If the file share is not open to everybody you will need to serve it up in the background from the file system via the web server.

You can use something like this "ASP.Net Serve File For Download" example (archived copy of 2).


Your first idea used to be the way but I've also noticed issues doing this using Firefox, try a straight http:// to the file - href='http://server/directory/file.xlsx'


You're going to have to rely on each individual's machine having the correct file associations. If you try and open the application from JavaScript/VBScript in a web page, the spawned application is either going to itself be sandboxed (meaning decreased permissions) or there are going to be lots of security prompts.

My suggestion is to look to SharePoint server for this one. This is something that we know they do and you can edit in place, but the question becomes how they manage to pull that off. My guess is direct integration with Office. Either way, this isn't something that the Internet is designed to do, because I'm assuming you want them to edit the original document and not simply create their own copy (which is what the default behavior of file:// would be.

So depending on you options, it might be possible to create a client side application that gets installed on all your client machines and then responds to a particular file handler that says go open this application on the file server. Then it wouldn't really matter who was doing it since all browsers would simply hand off the request to you. You would have to create your own handler like fileserver://.


You may need an extra "/"

<a href="file:///server/directory/file.xlsx">Click me!</a>