Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name, System.Text.Encoding.UTF8));
但这个只是针对没有空格和IE的情况下使用。
如果想在FireFox下输出没有编码的文件,并且IE下输出的文件名中空格不为+号,就要多一次判断了。
代码如下:
if (Request.UserAgent.ToLower().IndexOf("msie") > -1)
{
downloadfilename = HttpUtility.UrlPathEncode(downloadfilename);
}
if (Request.UserAgent.ToLower().IndexOf("firefox") > -1)
{
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + downloadfilename + "\"");
}
else
{
Response.AddHeader("Content-Disposition", "attachment;filename=" + downloadfilename);
}
查看更多关于在FireFox/IE下Response中文文件名乱码问题解决方案的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did34768