0

We have a network drive (G:) that houses public files, meaning anyone in the company can access it. I am needing to make a page that can dynamically find all the files in a given directory so I can display links for them.

Currently I would have to hardcode all the files like so:

<a target="_blank" href="file:\\\\\server\path\to\file.docx">Document</a>

This is a pain as the page is set up to work with multiple projects and these files are different for each project.

I am wondering if there is a way I can link to these files with some kind of JS or ASP classic loop.

So far I have tried MapNetworkDrive in ASP but kept getting this error

No network provider accepted the given network path.

Here is the ASP code I was using:

Set NetworkObject = CreateObject("WScript.Network")
set fs=Server.CreateObject("Scripting.FileSystemObject")

NetworkObject.MapNetworkDrive "", "\\Server\Folder", False, username, pass

set fo=fs.GetFolder("G:\Path\To\File.doc")

I also tried it without the MapNetworkDrive but had no success there either.

Since all of the users will have the Network drive mapped under G: on their local machines and have access to all the files, I figured there would be a way to do this with JS. I'm not having any luck finding anything though.

Additionally, I cannot simply upload all of the files to the webserver as it is a small server with limited space. It also seems redundant to have the same file on 2 different servers. Plus, this is a manual process and I'm not sure which files need to be accessed for all the different projects that already exist or are coming.

EDIT

All users that will be using this feature are using IE so cross browser is not an issue. Additionally, I am limited to Read-Write access so turning the network drive into a webserver or some admin-related solution is unfortunately not a viable solution to me.

2
  • You could list all the files using the filesystemobject, provided the user account running the ASP page has read access to the folder structure. What are you trying to acheive which would be more convenient for the end-user than just browsing the directories directly? Sep 17, 2013 at 0:47
  • @TimWilliams They want a central location to house links to all the different tools related to this series of projects. I updated the question to include the ASP code I tried. Sep 17, 2013 at 14:37

2 Answers 2

1
<a target="_blank" href="file:\\\\\server\path\to\file.docx">Document</a>

This should work in IE and Outlook/Word. It won't work in Chrome or Firefox, intentionally - the link will fail silently.

Linking to files on a network drive can be very tedious depending upon the browser. For example: https://stackoverflow.com/a/5109618/973155

Workaround:
Setup IIS on the network server and change the path to http://example.com/file.docx

EDIT: Make sure you enable directory browsing in IIS

3
  • I probably should have mentioned that I have Read-Write access to the servers but that is the extent of my abilities. I had seen that post you linked, all the users are going to be using IE anyway so cross-browser solutions are also not needed. Sep 16, 2013 at 18:10
  • 1
    @DavidStarkey not needed now != not needed. I used to be in a similar position where it was guaranteed that everyone is using IE; then the new marketing director changed that department to OSX, and Doctors started doing the BYOD with iPads and Android devices. Might as well jump in front of that before it becomes an actual problem.
    – AnonJr
    Sep 16, 2013 at 20:55
  • @DavidStarkey and getting back to Farhan's solution, you probably are better off adding the share as a virtual directory in IIS and writing the page to treat it like a local folder.
    – AnonJr
    Sep 16, 2013 at 20:57
0

I use the following on our internal site that is run with ASP for the same purpose.

jQuery File Tree is a configurable, AJAX file browser plugin for jQuery. Continuation of unmaintained jQuery File Tree (v1.01) (12 April 2008) from ABeautifulSite.net

https://github.com/daverogers/jQueryFileTree

The script is called as follows:

<script type="text/javascript">
        $(document).ready( function() {

            $('#container_id').fileTree({
              root: '/InetPub/wwwroot/whatever your site is',
              script: './includes/Connectors/jqueryFileTree.aspx',
              expandSpeed: 1000,
              collapseSpeed: 250,
              multiFolder: true
            }, function(file) {
                alert(file);
            });         
        });
</script>

I modified the script a bit because it would only list the files and not link properly by adding the following it will now open or download depending on your browsers abilities

<script type="text/javascript">
        function openFile(file) {
           window.open(file.replace("InetPub/wwwroot/",""));
        }

        $(document).ready( function() {

            $('#container_id').fileTree({
              root: '/InetPub/wwwroot/whatever your site is',
              script: './includes/Connectors/jqueryFileTree.aspx',
              expandSpeed: 1000,
              collapseSpeed: 250,
              multiFolder: true
            }, function(file) {
                openFile(file);
            });         
        });
</script>

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.