在文件服务器上创建下载链接到文件 [英] Creating download link to a file on a file server

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

问题描述

我正在寻找一种方式来(很容易,由preference;))创建一个单独的文件服务器上的下载链接到文件

I'm looking for a way to (easily, by preference ;)) create a download link to a file on a separate file server.

的情况如下:应用程序我发展(在vb.net asp.net 2.0,但我有一个类似的问题在C#中,任何一种解决方案对我的作品)将被用于公司内部运行。
由于是很好的做法,文件存储和Web应用程序都在两个单独的服务器。

The situation is as follows: the application I'm developing (asp.net 2.0 in vb.net but I have a similar issue in c#, either solution works for me) will be run internally for a company. As is good practice, the file storage and web application are on two separate servers.

基本上,我需要能够创建一个下载链接到一个文件中,唯一可用的网址我需要访问该文件的 \\服务器\\文件夹1 \\文件夹2 \\ folder3 \\ file.txt的的(可是任何类型的文件)

I basically need to be able to create a download link to a file, the only available URL i have to access the file is \servername\folder1\folder2\folder3\file.txt (can be any sort of file)

友情链接根本不工作。这是它是如何当前设置:

Weblinks simply don't work. This is how it's currently set up:

tablerowfield.Text = String.Format(
    "<a href=""\\servername\folder1\folder2\folder3\{0}"" 
        target=""_blank"">Click me</a>",
    filename)

这并不显而易见的原因工作。它曾经被设置为写文件到应用程序的路径本身和工作完美,但它不是好的做法,这就是为什么我改变它(或尝试)。

Which doesn't work for obvious reasons. It used to be set up to write that file to the application path itself and that worked perfectly, but it isn't good practice and that's why I'm changing it (or trying to).

我读到创建一个下载页面,然后在你的数据库表中持有的链接,并返回正确的Web网址下载,但我面对时间紧迫遗憾的是没有让我来开发。解决方案

I read solutions about creating a download page and then having a table in your DB which holds the links and returns the proper web URL for download but the time constraint I am faced with unfortunately doesn't allow me to develop that.

假设我可以提供完整的文件路径,以象上面的文件中的字符串,什么是只创建一个链接的最简单的方法是,点击后,下载文件?

Assuming I can provide a string with the full filepath to the file like the above, what is the easiest way to just create a link that, when clicked, downloads the document?

注:我在这个环境中0管理员权限。这真不是我的帮助。假设我给像上面正确的链接,并有相应的文件访问权限和等。

Note: I have 0 admin rights in this environment. That really isn't helping me. Let's assume I am given the correct link like above and have the appropriate file access rights and such.

更新:

上面的例子不工作在IE,但不是在Firefox和Chrome。 IE浏览器将其转换为一个文件://服务器/ ...链接,做什么它应该,但FF和Chrome都积极决定,这是不安全的,并从他们的浏览器禁用它。

The above example does work in IE, but not in Firefox and Chrome. IE converts it to a file://servername/... link which does what it's supposed to, but FF and Chrome both actively decided that this is unsafe and have disabled it from their browsers.

推荐答案

您可以使用ASHX文件(比如说,downloadfile.ashx)并使用以下code(未测试,但它会是类似的东西)的它:

You can use ASHX file (say, downloadfile.ashx) and use the following code (not tested, but it will be something like that) in it:

 Response.Clear();
 Response.ContentType = "application/octet-stream";
 Response.AddHeader("Content-Disposition", "attachment; filename=abc.txt");                                            
 Response.WriteFile(Server.MapPath("\\servername\folder1\folder2\folder3\abc.txt"));
 Response.End();

然后用这个在你的锚标记,如:

and then use this in your anchor tag like:

<a href="downloadfile.ashx"  target=""_blank"">Click me</a>

请注意:您还可以传递参数下载不同的文件,如:

Note: You can also pass parameters for downloading different files like:

<a href="downloadfile.ashx?file=abc.txt"  target=""_blank"">Click me</a>

,然后在ashx的文件,使用文件名来下载相应的文件。

and then, in ashx file, use the file name to download the appropriate file.

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

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