下载带有英寸;&QUOT文件;或QUOT;#"在文件名文件名废墟 [英] Downloading file with ";" or "#" in file name ruins filename

查看:116
本文介绍了下载带有英寸;&QUOT文件;或QUOT;#"在文件名文件名废墟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为AttachmentDownload.aspx文件和Pag​​e_Load方法里面有这样code至极提供了下载文件。所有名称在IE中正常工作,但其中包括名称,要么 #。他们提供的用户将文件保存在名为AttachmentDownload.aspx。对此有一个解决方法吗?

下面是一个例子:

 变种文件名= Server.UrlPathEn code(%TXT。);
Response.AddHeader(内容处置的String.Format(附件;文件名= \\{0} \\,文件名));
Response.WriteFile(路径);
到Response.End();


解决方案

UrlPathEn code 只带codeS中的一个URL等形成串的路径部分,可以尝试使用
Server.UrlEn code 或的 HttpUtility.UrlEn code

I have a file named AttachmentDownload.aspx and inside Page_Load method have such code wich offers to download file. All names work correctly in IE except names which include ";" or "#". They offer user to save the file under name "AttachmentDownload.aspx". Is there a workaround for this?

Here is an example:

var fileName = Server.UrlPathEncode (";%.txt");
Response.AddHeader("content-disposition", String.Format("attachment;filename=\"{0}\"", fileName));
Response.WriteFile(path);
Response.End();

解决方案

UrlPathEncode only encodes the "Path" portion of a URL-like formed string, try using Server.UrlEncode or HttpUtility.UrlEncode.

这篇关于下载带有英寸;&QUOT文件;或QUOT;#"在文件名文件名废墟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆