下载文件变成了aspx页面

Aderlee 2006-12-04 11:31:42
Response.Clear();

// Specify the Type of the downloadable file.
Response.ContentType = "application/octet-stream";

// Set the Default file name in the FileDownload dialog box.
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlPathEncode(strFile));
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
Response.Flush();

// Download the file.
Response.WriteFile(strFile);
其中strFile为特定指定路径的文件名,如:D:\05.doc
可是点击下载的时候,老是默认文件名是当前页面的名称,跟踪的strFile显示的明明是D:\05.doc,请教高手,怎么办??????
...全文
1054 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yan63 2006-12-04
  • 打赏
  • 举报
回复
页面上就放一个按钮试试。我测试过没有问题
string strFile = @"D:\test.rar";
int index = strFile.LastIndexOf('\\');
string filename = strFile.Substring(index + 1);
Response.Clear();

// Specify the Type of the downloadable file.
Response.ContentType = "application/octet-stream";

// Set the Default file name in the FileDownload dialog box.
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlPathEncode(filename));
Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
// Response.Flush();

// Download the file.
Response.WriteFile(strFile);
Response.End();
Aderlee 2006-12-04
  • 打赏
  • 举报
回复
好像都不行,郁闷中……,跟前台代码会不会有关系呢
Snowdust 2006-12-04
  • 打赏
  • 举报
回复
Response.Clear();
Response.Buffer = true;
Response.Charset = "UTF-8";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strFile, System.Text.Encoding.UTF8) + ";charset=gb2312");
Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
Response.ContentType = "application/octet-stream";
yan63 2006-12-04
  • 打赏
  • 举报
回复
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFile);
yan63 2006-12-04
  • 打赏
  • 举报
回复
string strFile= Server.UrlEncode(filePath)
Response.AddHeader("Content-type", "application/file");
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
Response.WriteFile(strFile);
hy_lihuan 2006-12-04
  • 打赏
  • 举报
回复
晚了
Aderlee 2006-12-04
  • 打赏
  • 举报
回复
yan63(silence like a cancer grows)和cpp2017(幕白兄)是对的,谢谢,各位,撒分了
cpp2017 2006-12-04
  • 打赏
  • 举报
回复
哦,不好意思,我忘了说了,我的按钮是放在DataList里的
==========

注意:去掉Response.Flush();
最后加上Response.End();
HJS1820 2006-12-04
  • 打赏
  • 举报
回复
幫頂
結帖時接點分
Aderlee 2006-12-04
  • 打赏
  • 举报
回复
哦,不好意思,我忘了说了,我的按钮是放在DataList里的
cpp2017 2006-12-04
  • 打赏
  • 举报
回复
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(strFile, System.Text.Encoding.UTF8));

这样写应该是可以的.
国际学术期刊Science/AAAS和英特尔在全球首次联袂推出第一季《架构师成长计划》以来,吸引了无数架构师踊跃参与,获得业内广泛赞誉。为持续助力架构师把握数智机遇,构建未来,第二季《架构师成长计划》全新升级,强势归来!业内顶尖架构师大咖齐聚,为架构师群体量身打造系统成长课程,带来涵盖云游戏、云原生、联邦学习、生信大数据、算力网络、云网融合等多个热门话题的前沿技术及案例实践。第一期:超视频时代 音视频架构建设与演进复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=298&tc=yxq0921l2d&frm=csdn_2第二期:转化医学研究背景下的高性能计算平台复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=311&tc=pzw21rx59o&frm=csdn_2第三期:联邦学习的研究与应用实践复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=315&tc=0e8trfvt8i&frm=csdn_2第四期:用架构思维为云原生做减法复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=316&tc=i2kgf55ggn&frm=csdn_2第五期:网络智能化技术与演进复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=322&tc=ckhvmonqvb&frm=CSDN_2第六期:异构计算 数据中心“芯”变革复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=325&tc=mzppx1h6ri&frm=csdn_2第七期:筑算力,话东西复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=327&tc=gwb7n8x79n&frm=csdn_2第八期:AI驱动的生命科学创新范式之变复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=328&tc=zircyqwy9u&frm=csdn_2第九期:软硬一体实现数据库性能优化复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=348&tc=4a46kfrb0o&frm=csdn_2第十期:AI规模化应用时代的深度学习平台构建复制链接收看完整内容:https://bizwebcast.intel.cn/eventstart.aspx?eid=349&tc=fm9a1mrumb&frm=csdn_2

62,046

社区成员

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

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

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

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