◆下载文件名中◆
我用如下过程来进行下载文件,但是要下载的文件名含有中文的情况下
无法接收中文(自动把中文截取掉,比如:“aa测试1.xls” 被截取为 “aa1.xls”)
或者是乱码
private void download(string filename)
{
string spath = Server.MapPath("ExcelDownload\\" + filename);
System.IO.FileInfo file = new System.IO.FileInfo(spath);
if (file.Exists)
{
Response.ContentType = "excel/xls";
//Response.HeaderEncoding = System.Text.Encoding.GetEncoding("GB2312");
filename = Server.UrlEncode(filename);
//加入上面这句中文部分被自动截取,如果注释掉,中文部分则是乱码
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename);
//Response.TransmitFile(spath);
Response.WriteFile(spath);
Response.End();
}
else
{
Response.Write("下载的文件不存在!");
}
}
我已经在web.config的system.web中加入如下代码:
<globalization requestEncoding="GB2312" responseEncoding="GB2312" uiCulture="zh-CN" culture="zh-CN" fileEncoding="GB2312" />
但还是不行,请高手帮忙
环境:win2003 + iis6.0+ ie6.0
------解决方案-------------------- Response.Clear()
Response.Charset = "UTF-8"
Response.Buffer = True
Me.EnableViewState = False
Response.ContentEncoding = System.Text.Encoding.UTF8
加上这些代码