asp.net+c#中如何实现文件下载?

hhren 2003-10-31 06:37:16
如题所述,有源码吗?
...全文
47 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
osborne 2003-11-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();
xieyi80 2003-11-01
  • 打赏
  • 举报
回复
将要下载的文件打包(.rar格式),然后链接就可以了!
大户翁 2003-11-01
  • 打赏
  • 举报
回复
直接链接到要下载的文件 就可
madong 2003-10-31
  • 打赏
  • 举报
回复
我觉得你的分有点少了
帮你up下

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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