Click here to Skip to main content
16,017,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing an intranet web application to enable users to store and download files from the servers local hard drive. I am presenting users with a jquery treeview to select the files from. The treeview returns the full absolute path of the file. This all works fine, my issue is as follows.

I cannot seem to find a way to enable the users to download the files from there. I have tried the following:

In Javascript
window.open('file:///c://Documents/folder/file.ext', 'Download');


In HTML
<a href="file:///C://Documents/folder/file.ext">Download Me</a>


Neither of these do anything. If I enter the address provided in either of those instances directly into the url of my browser, I get the desired effect. Please assist me in finding a way to achieve this goal in the click event of my javascript.

Thanks
Posted
Updated 22-Oct-10 6:30am
v2
Comments
William Winner 22-Oct-10 12:11pm    
that works for you because I assume you are accessing the link from the server itself. file:/// tells the browser to look on the local computer for the file. So if you use a browser on your server, it looks on the servers hard-drive.

However, if Joe Schmo uses his computer (not the server) and types that into his browser, it will look for that file on Joe Schmo's computer.

Okay, well I guess I've taken the incorrect approach entirely. My intention was to enable the user to download the file from the servers hard-drive. My treeview contains the current file structure for a directory on the server, and I would like to enable users to download any file present.

Currently, when a user selects a file, a javascript event is fired. My goal is to use this javascript event to open the download for the user. My function is filled with the parameter of the local address to the server. So if I have this local address (on the servers hard-drive), how can I enable the user to download this file (to their local hard-drive)?


My basic server folder structure looks like.
Documents
TreeViewDirectory
WWW Directory (Where site is hosted)

And I have a javascript function on the page collecting data from a post from which I want to enable the user to download the file.
function(serverFileAddress)<br />
{<br />
//currently its <br />
window.open(serverFileAddress, 'Download');<br />
<br />
//what should it be?<br />
}<br />


serverFileAddress will return the proper download if navigated to through the url address.

Thank you.
 
Share this answer
 
Comments
Abdulrahman Elissawi 28-Jul-24 11:17am    
HiI got nothing to help you with, cuz I'm a normal user with ZERO coding experience...

I'm here cuz I need your help, and found that your question related to the thing I wanted to do for a long time


Is there a script for windows that I can use to get the direct download link (download link from the server) for an local download or update being downloading through the app itself

So I can take that direct download link and manually download it through browser or using a download manager for better options like more speed and pause feature...
You need the opposite of Server.MapPath like this:

VB
Public Function MapURL(ByVal Path As String) As String
     Dim AppPath As String = _
     HttpContext.Current.Server.MapPath("~")
     Dim url As String = String.Format("~{0}" _
     , Path.Replace(AppPath, "").Replace("\", "/"))
     Return url
End Function

Source: http://geekswithblogs.net/AlsLog/archive/2006/08/03/87032.aspx[^]

This will translate the file path to an url that will work for your users.

Good luck!
 
Share this answer
 
Thanks for the answer E.F., but I don't think that is a solution that will work for me. That method seemed to simply return the location of the application + the path parameter:

i.e.: C:\\Documents\\usr\\www Folder\\Current Application\\ + filled parameter

But in this case, my parameter is actually the full physical address for the file on the servers hard-drive. My post returns something similar to:

C:\\Documents\\usr\\File Structure\\Treeview Directory\\filename.ext

I already have the exact address on the physical hard-drive. Now I need to use that to provide a download from a javascript method. I believe part of my issue is related to the fact that the treeview structure doesn't reside in the application, it sits higher in my file structure.

C:\\
::Documents
:::USR
::::File Structure
:::::Treeview Directory
::::::File1.ext
::::::File2.ext
::::::File3.ext
::::WWW Folder
:::::Current Application Folder

I really want to avoid having the treeview folder structure under the application. This file structure is used for a good deal of other activities, and would like to maintain its independence.

Is there a way to link to this file? When I try to link directly to the file i.e. (|a href="c://documents//usr//file structure//treeview directory//file1.ext"|DL|/a|) i get an error that the file is unable to be opened because the file isn't associated with any program

This seems like it should be so simple, but yet I've been baffled by it for hours. I apologize for my ignorance, any assistance is greatly appreciated. Thanks.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900