如何在asp.net中实现文件下载 [英] How to implement a file download in asp.net

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

问题描述

什么是最好的方法来实现,从一个网页的一个下载动作使用asp.net 2.0?



日志文件的动作是创建在一个名为[应用程序根目录] /日志。我有完整的路径,并希望提供一个按钮,当点击将下载日志文件从IIS服务器到用户本地pc。

解决方案

这是否有帮助:



http://www.west-wind.com/weblog/posts/76293.aspx

  Response.ContentType =application / octet-stream; 
Response.AppendHeader(Content-Disposition,attachment; filename = logfile.txt);
Response.TransmitFile(Server.MapPath(〜/ logfile.txt));
Response.End();

Response.TransmitFile是发送大文件而不是Response.WriteFile的接受方式。 >

What is the best way to implement, from a web page a download action using asp.net 2.0?

Log files for a action are created in a directory called [Application Root]/Logs. I have the full path and want to provide a button, that when clicked will download the log file from the IIS server to the users local pc.

解决方案

Does this help:

http://www.west-wind.com/weblog/posts/76293.aspx

Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition","attachment; filename=logfile.txt");
Response.TransmitFile( Server.MapPath("~/logfile.txt") );
Response.End();

Response.TransmitFile is the accepted way of sending large files, instead of Response.WriteFile.

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

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