20

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?

1
  • What exactly is the problem? Those both seem like they should work (well, I don't know much VBScript, but it assuming that code's correct...).
    – Asmor
    Sep 19, 2008 at 12:50

9 Answers 9

17

Try formatting the link like this (looks hellish, but it works in Firefox 3 under Vista for me) :

<a href="file://///SERVER/directory/file.ext">file.ext</a>
7
  • Awesome. I knew it had to be something simple. Works for me in Ffx and IE. I'm using XP, for the record. Sep 19, 2008 at 13:04
  • 1
    I think you may actually have one too many slashes. You need 2 for the file:// protocol and 2 for the server name //SERVER/. Jan 27, 2009 at 17:42
  • Works for me with the five slashes, not with the four that you'd expect to need. Don't ask me why ... Jan 29, 2009 at 12:21
  • 1
    en.wikipedia.org/wiki/File_URI_scheme#Mozilla the fifth slash separates the implied localhost after file:// from the server //SERVER
    – Simon D
    Oct 31, 2011 at 2:23
  • 2
    Pretty sure this little hack ain't working in Google Chrome no more, at least I can't get it to work in my application :(
    – Vidar
    Mar 7, 2013 at 18:41
2

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

1
  • Works in IE, but not firefox. Going to try suggestion by typemismatch. Sep 19, 2008 at 12:53
1

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

1

You may need an extra "/"

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

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).

1
  • In this case, the authentication is already being done before they get to this web page. Anyone who gets here should have access to these files, and to the directory in which they are stored. I really want to keep this simple. Sep 19, 2008 at 12:57
0

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 ...

1
  • I agree. So how do I implement such a simple link in HTML? Sep 19, 2008 at 13:02
0

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://.

0

This works in Firefox 96 in macOS 12, and should work in other browsers and in Windows too:

<a href="smb://server/location">open file</a>
-1

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'

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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