使用NET如何实现文件下载(以流的形式输出下载)
要实现这种下载方式,形式为,直接弹出保存对话框,让客户端选择保存并下载!
前提是:先引入命名空间:
using System.IO;
以下就是实现过程,敬请查看!
FileInfo DownloadFile = new FileInfo(“这里填写阁下的文件路径,填写个完整的路径,否则就完完了”); Response.Clear(); Response.ClearHeaders(); Response.Buffer = false; Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8)); Response.AppendHeader("Content-Length", DownloadFile.Length.ToString()); Response.WriteFile(DownloadFile.FullName); Response.Flush(); Response.End();
才疏技短,见笑见笑!
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18