.net中 下载中文文件名的乱码问题

首先是Encoding

Response.ContentEncoding = System.Text.Encoding.UTF8;
然后是FileName的地方用System.Web.HttpUtility.UrlEncode(name)

然后把用于响应输出的aspx文件保存为UTF-8格式
最后是在webconfig里面设置

<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"/>

byte[] filebyte = (byte[])objSet.Tables[0].Rows[0]["BGNR"];
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + System.Web.HttpUtility.UrlEncode(objSet.Tables[0].Rows[0]["FILENAME"].ToString()) + "\"");
Response.ContentType = "application/x-msdownload;Charset=utf-8";
                   
Response.BinaryWrite(filebyte);

阅读更多

没有更多推荐了,返回首页