37

Is there a way to incorporate a working link to a Windows shared folder into an HTML page? E.g. a link to \\server\folder\path?

For simplicity, let's say the page will be opened on a Windows machine (and on the same intranet where the server is located, of course.)

I've tried a few tricks with file:// scheme, but none of them seemed to work.

hippietrail
  • 13,703
  • 15
  • 87
  • 133
alex
  • 835
  • 1
  • 7
  • 9

4 Answers4

33

I think there are two issues:

  1. You need to escape the slashes.
  2. Browser security.

Explanation:

  1. I checked one of mine, I have the pattern:

    <a href="file://///server01\fshare\dir1\dir2\dir3">useful link </a>
    

    Please note that we ended up with 5 slashes after the protocol (file:)

  2. Firefox will try to prevent cross site scripting. My solution was to modify prefs.js in the profile directory. You will add two lines:

    user_pref("capability.policy.localfilelinks.checkloaduri.enabled", "allAccess");
    user_pref("capability.policy.localfilelinks.sites", "http://mysite.company.org");
    
Shadow The Vaccinated Wizard
  • 62,584
  • 26
  • 129
  • 194
Bill
  • 1,252
  • 10
  • 20
  • 1
    Yes, browser security is the issue. But I don't know if target browser is Firefox. Any other ideas? – alex Apr 27 '11 at 05:21
  • Take a look at the answer to a similar question, where IE should work, Firefox can be adjusted, but other major browsers block this. [stackoverflow.com/questions/855614](http://stackoverflow.com/questions/855614) – Bill Apr 27 '11 at 16:32
  • Do I need to configure browser's settings first? Cheers! – StanLe3 Jun 12 '18 at 03:27
9

File protocol URIs are like this

file://[HOST]/[PATH]

that's why you often see file URLs like this (3 slashes) file:///c:\path...

So if the host is server01, you want

file://server01/folder/path....

This is according to the wikipedia page on file:// protocols and checks out with .NET's Uri.IsWellFormedUriString method.

1

If you are allowed to go further then javascript/html facilities - I would use the apache web server to represent your directory listing via http.

If this solution is appropriate. these are the steps:

  1. download apache hhtp server from one of the mirrors http://httpd.apache.org/download.cgi

  2. unzip/install (if msi) it to the directory e.g C:\opt\Apache (the instruction is for windows)

  3. map the network forlder as a local drive on windows (\server\folder to let's say drive H:)

  4. open conf/httpd.conf file

  5. make sure the next line is present and not commented

    LoadModule autoindex_module modules/mod_autoindex.so

  6. Add directory configuration

<Directory "H:/path">

Options +Indexes

AllowOverride None

Order allow,deny

Allow from all

</Directory> 7. Start the web server and make sure the directory listingof the remote folder is available by http. hit localhost/path 8. use a frame inside your web page to access the listing

What is missed: 1. you mignt need more fancy configuration for the host name, refer to Apache Web Server docs. Register the host name in DNS server

  1. the mapping to the network drive might not work, i did not check. As a posible resolution - host your web server on the same machine as smb server.
Pavlonator
  • 869
  • 1
  • 9
  • 21
-2

This depend on how you want to incorporate it. The scenario 1. click on a link 2. explorer window popped up

<a href="\\server\folder\path" target="_blank">click</a>

If there is a need in a fancy UI - then it will barely serve as a solution.

Pavlonator
  • 869
  • 1
  • 9
  • 21
  • 5
    I think this won't work unless the HTML itself is loaded with `file://` URI scheme. At least it doesn't work with the WebKit-based Chrome. – alex Apr 27 '11 at 05:23