解决方法很简单:用双引号把文件名括起来:
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
Response.ContentType = "application/octet-stream";
Response.ContentType = "application/octet-stream";
不过还是有一个问题没解决,在IE中,如果文件名包含两个英文名点(period, 字符'.')的话,它会在第一个点前自动加个"[1]",于是你原来的文件名"aaa.bbb.whatever"就变成了"aaa[1].bbb.whatever". 哪位知道怎么解决这个问题,给大家分享一下?
--------
Update: 根据微软的说明,第二个问题根本就无法解决。
我说,大家一起劝用户们扔掉IE吧!
--------
Update:
第二个问题可以这样解决:
if (Request.Browser.Browser.Contains("IE"))
{
string ext = fileName.Substring(fileName.LastIndexOf('.'));
string name = fileName.Remove(fileName.Length - ext.Length);
name = name.Replace(".", "%2e");
fileName = name + ext;
}
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
Response.ContentType = "application/octet-stream";
{
string ext = fileName.Substring(fileName.LastIndexOf('.'));
string name = fileName.Remove(fileName.Length - ext.Length);
name = name.Replace(".", "%2e");
fileName = name + ext;
}
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
Response.ContentType = "application/octet-stream";