怎么下载文件??

bhys 2003-12-01 05:47:04
怎么下载文件,文件不是压缩格式.
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(scfilename, System.Text.Encoding.UTF8))
Response.WriteFile(filepath)
Response.End()
下面的程序有点问题.下载时弹出的信息不正确.下载文本文件时会自动加一串代码进去,怎么解决..
...全文
57 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gasover 2003-12-01
  • 打赏
  • 举报
回复
string path = Server.MapPath(Request.Params["File"]);
System.IO.FileInfo file = new System.IO.FileInfo(path);

// clear the current output content from the buffer
Response.Clear();
// add the header that specifies the default filename for the Download/SaveAs dialog
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
// add the header that specifies the file size, so that the browser
// can show the download progress
Response.AddHeader("Content-Length", file.Length.ToString());
// specify that the response is a stream that cannot be read by the
// client and must be downloaded
Response.ContentType = "application/octet-stream";
// send the file stream to the client
Response.WriteFile(file.FullName);
// stop the execution of this page
Response.End();
bhys 2003-12-01
  • 打赏
  • 举报
回复
我要下载的文件不是压缩格式呀
shang515 2003-12-01
  • 打赏
  • 举报
回复
看看这个
http://expert.csdn.net/Expert/TopicView1.asp?id=2513663
待接入自我 2003-12-01
  • 打赏
  • 举报
回复
呵呵,一个土办法:Response.redirect("......../aa.txt")
不过,文本文件会被打开的,
zip等文件,则会自动弹出windows下载工具

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧