读书人

怎么解决http输出 中文的文件名时出现

发布时间: 2012-01-31 21:28:41 作者: rapoo

如何解决http输出 中文的文件名时出现 文件名乱码的问题

如何解决http输出 中文的文件名时出现 文件名乱码的问题?用了response.Charset = "UTF-8 "; 也不行,在“文件下载”对话框中显示的文件名,如果该文件名是纯字母的或纯数字的,就会显示正确的文件名;如果该文件名是 中文汉字的,就出现乱码,如何解决这个问题啊?谢谢!
FileInfo file = new System.IO.FileInfo(request.PhysicalPath);

response.Clear();

response.AddHeader( "Content-Disposition ", "attachment; filename= " + file.Name);

response.AddHeader( "Content-Length ", file.Length.ToString());

response.Charset = "UTF-8 ";

string fileExtension = file.Extension.ToLower();

switch (fileExtension)
{

case ".mp3 ":
response.ContentType = "audio/mpeg3 ";
break;

case ".mpeg ":

response.ContentType = "video/mpeg ";
break;

case ".jpg ":

response.ContentType = "image/jpeg ";
break;

case "bmp ":

response.ContentType = "image/bmp ";
break;

case ".gif ":


response.ContentType = "image/gif ";
break;

case ".doc ":

response.ContentType = "application/msword ";

break;
case ".xls ":

response.ContentType = "application/vnd.ms-excel ";
break;
case ".css ":

response.ContentType = "text/css ";
break;

default:

response.ContentType = "application/octet-stream ";
break;

}

response.WriteFile(file.FullName);

response.End();

[解决办法]
用GB2312编码
[解决办法]
还是字符集的问题,GB2312试试

再不行就一个个试,网络上有Charset 集合

再不行,看看你的WEB.CONFIG里设置的Charset
[解决办法]
"UTF-8 ";用这种格式!问题不解决你抽我!

读书人网 >asp.net

热点推荐