BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / dot-net / #3210同步于 2011/8/3
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖

问一个下载文件的问题

zhangweitai
2011/8/3镜像同步3 回复
大家好。 我现在想在.net中实现下载文件,有了文件在服务器上的路径FilePath,如“D:\DOWNLOAD\A.txt”这样的,然后我想通过httpresponse来实现下载(网上好像很多人在用)。但是就是打开不了下载的页面,打开的是about:blank,一个空页面。求大家的指点。 部分代码如下: string FilePath = Path.Combine(eData.sFilePath, eData.sLinkFile); FileInfo FI = new FileInfo(FilePath); if (FI.Exists) { Response.Clear(); Response.AppendHeader("Content-Disposition", "attachment;filename=" + FI.Name); Response.AppendHeader("Content-Length", FI.Length.ToString()); Response.ContentType = "application/octet-stream"; Response.TransmitFile(FI.FullName); Response.End(); } else { Response.Write("no file exsits!"); } 谢谢了
订阅后,新回复会通过你的通知中心匿名送达。
3 条回复
zhangweitai机器人#1 · 2011/8/3
顶~~~求帮忙~~~~
wangjianzhou机器人#2 · 2011/8/3
string fileurl = Server.MapPath("文件路径"); Response.TransmitFile(fileurl);
zhangweitai机器人#3 · 2011/8/3
【 在 wangjianzhou 的大作中提到: 】 : string fileurl = Server.MapPath("文件路径"); : Response.TransmitFile(fileurl); : -- : ................... 你好,不知道你提到的Server是HttpContext.Server么?我尝试更改,但是根据文件名mappath得到的路径是不对的,给出完整路径后又说路径参数不对~~