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

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

问题描述

什么是使用来实现,从网页下载行动的最佳途径asp.net 2.0?

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

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

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.

推荐答案

这是否帮助:

<一个href=\"http://www.west-wind.com/weblog/posts/76293.aspx\">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。

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

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

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