C#.net文件下载 [英] c# .net file download

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

问题描述

我该怎么做才能允许客户端从我的网站下载文件?

what do i do to allow a client to download a file from my website?

推荐答案

一旦您在网页中提供了指向文件的链接,客户端浏览器将负责下载.
尝试在ASP.NET中下载文件并跟踪下载成功/失败的状态 [
Once you provide a link to your file in the web page, the client browser will take care of the download.
Try File Download in ASP.NET and Tracking the Status of Success/Failure of Download[^].


对于某些文件类型,Web服务器(IIS)不知道该怎么做或阻止出于安全原因下载它们(.mdb).最简单的解决方案是压缩要下载的文件-扩展名.zip通常已注册.否则,您可能需要在IIS中注册新的文件类型.
With some file types, the web server (IIS) does not know what to do or blocks their download for security reasons (.mdb). The easiest solution is to zip the files which are to be downloaded - the extension .zip is normally registered. Otherwise you may need to register a new file type with IIS.


我不了解您的关注,但很可能您只是不了解一些非常基本的知识.如果您希望用户下载某些文件,则只需编写以下内容即可:

I don''t understand your concern, but most likely you just don''t understand some very basic things. If you want the user to download some file, you can simply write:

<a href="somefile.pdf'>Some PDF document</a>



单击锚点时,如果客户端在浏览器中嵌入了PDF支持或作为插件可用,则会将其加载到页面中,否则用户可以选择下载它或使用某些查看器打开,默认情况下或由用户使用的选择;在所有情况下,用户都可以像通常使用锚一样简单地下载文件.对于其他文件类型(通常为* .zip),唯一的选择是下载.此代码假定您将文件放置在与当前页面相同的目录中,但是它可以是相对于此页面的任何目录.避免使用绝对路径,或者仅使用完整的URL(以方案开头).

抱歉,这太琐碎了,您已经知道所有这些,但实际上可以回答您的问题.如果您需要一些额外的下载功能,请特别询问它们.但是最好从这里开始,希望您以后可以学习高级知识.

关于您对错误403的问题,请在解决方案1的讨论中参阅我的评论中的答案.

有关此问题,另请参见:
http://msdn.microsoft.com/en-us/library/system. web.httpserverutility.mappath.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/ms524632%28v = vs.90%29.aspx [ ^ ].

你有主意吗?通常,应用程序是在沙盒环境中的HTTP服务器下执行的,该沙箱环境排除了对映射到该站点的根目录之外的任何目录的访问.

—SA



On anchor click, if the client has PDF support embedded in browser or available as plug-in, it will be loaded in the page, otherwise the user will get a choice do download it or open with some viewer, default or by the user''s choice; in all cases, the user can simply download the file, as always with the anchor. With other file types (very typically, *.zip), the only option will be downloading. This code assumes that you place the file in the same directory as the present page, but it can be any directory relative to this page. Avoid using absolute paths, or use just the full URL, starting with the scheme.

Sorry if this is too trivial and you already know all that, but it actually answers your question. If you need some extra downloading features, ask about them specifically. But better start from here and hopefully you will be able to learn advanced things later.

As to your question on your error 403, please see the answer in my comment, in the discussions of the Solution 1.

On this problem, see also:
http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath.aspx[^],
http://msdn.microsoft.com/en-us/library/ms524632%28v=vs.90%29.aspx[^].

Are you getting the idea? Normally, the applications are executed under HTTP server in a sandboxed environment which exclude the access to any directories outside the root directory mapped to the site.

—SA


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

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