本地文件下载链接 [英] Local File Download Link

查看:74
本文介绍了本地文件下载链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Intranet Web应用程序,以使用户能够从服务器本地硬盘驱动器存储和下载文件.我正在向用户展示一个jquery树形视图,以从中选择文件.树视图返回文件的完整绝对路径.一切正常,我的问题如下.

我似乎找不到能使用户从那里下载文件的方法.我尝试了以下方法:

用Javascript

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'');



在HTML中



In HTML

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



这些都不做任何事情.如果我将其中任一实例中提供的地址直接输入到浏览器的url中,都可以达到预期的效果.请协助我在我的javascript的click事件中找到实现此目标的方法.

谢谢,



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

推荐答案

好吧,我想我完全采用了错误的方法.我的意图是使用户能够从服务器硬盘驱动器下载文件.我的树形视图包含服务器上目录的当前文件结构,并且我希望使用户能够下载存在的任何文件.

当前,当用户选择文件时,将触发javascript事件.我的目标是使用此javascript事件为用户打开下载.我的函数充满了服务器本地地址的参数.因此,如果我具有此本地地址(在服务器硬盘驱动器上),如何使用户能够将此文件下载到(在其本地硬盘驱动器上)?


我的基本服务器文件夹结构如下所示.
文件
TreeViewDirectory
WWW目录(托管网站的地方)

而且我在页面上有一个javascript函数,该函数从帖子中收集数据,我希望用户可以从该帖子中下载文件.
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 />



如果通过URL地址导航到serverFileAddress,则会返回正确的下载.

谢谢.



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

Thank you.


您需要像这样的Server.MapPath的反面:

You need the opposite of Server.MapPath like this:

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


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

这会将文件路径转换为适合您的用户的网址.

祝您好运!


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!


感谢您的回答E.F.,但我认为这不是对我有用的解决方案.该方法似乎只是返回应用程序的位置+ path参数:

即:C:\\ Documents \\ usr \\ www Folder \\ Current Application \\ +填充参数

但是在这种情况下,我的参数实际上是服务器硬盘驱动器上文件的完整物理地址.我的帖子返回的内容类似于:

C:\\ Documents \\ usr \\文件结构\\ Treeview目录\\ filename.ext

我已经在物理硬盘驱动器上有确切的地址.现在,我需要使用它来提供从javascript方法下载的内容.我相信我的问题的一部分与以下事实有关:树视图结构不驻留在应用程序中,而它在我的文件结构中位于更高的位置.

C:\\
::文件
::: USR
::::文件结构
::::: Treeview目录
:::::: File1.ext
:::::: File2.ext
:::::: File3.ext
:::: WWW文件夹
:::::当前应用程序文件夹

我真的想避免在应用程序下使用treeview文件夹结构.该文件结构用于许多其他活动,并希望保持其独立性.

有没有办法链接到这个文件?当我尝试直接链接到文件(即|| a href ="c://documents//usr//文件结构//treeview目录//file1.ext" | DL |/a |)时,出现错误消息该文件未与任何程序关联,因此无法打开该文件

似乎应该这么简单,但是我已经被它迷惑了好几个小时了.我为自己的无知表示歉意,非常感谢您的协助.谢谢.
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.


这篇关于本地文件下载链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆