星空网 > 软件开发 > ASP.net

从服务器下载文件中文名乱码解决方法

 try    {      string excelName = Request["excelName"].ToString(); //文件路径      string fileName = Request["fileName"].ToString(); //下载的文件名      if(!(string.IsNullOrEmpty(excelName)|| string.IsNullOrEmpty(fileName)))      {        Response.Charset = "GB2312";        Response.ContentEncoding = Encoding.GetEncoding("GB2312");        Response.ContentType="application/vnd.ms-excel";        //火狐浏览器不需将中文文件名进行编码格式转换        if (Request.ServerVariables["http_user_agent"].ToLower().IndexOf("firefox") == -1)        {          excelName = HttpUtility.UrlEncode(excelName, System.Text.Encoding.UTF8);        }        Response.AppendHeader("Content-Disposition", "attachment;filename=" +excelName);        Response.WriteFile(fileName);        Response.Flush();        Response.Close();      }    }    catch    { }

 注意判断浏览器 IE需要将中文文件名编码格式转换,而firefox浏览器则不用,不然下载下来的中文文件名会乱码




原标题:从服务器下载文件中文名乱码解决方法

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

TikTok热度50亿!亚马逊更是卖到脱销!警惕这类产品陷入侵权风暴……:https://www.kjdsnews.com/a/1480681.html
亚马逊在中国推出其全球首个集成第三方跨境头程物流解决方案:https://www.kjdsnews.com/a/1480682.html
8年估值80亿,Casper把“睡觉”这门生意做得很有新意:https://www.kjdsnews.com/a/1481661.html
谷歌教你网站出海,解锁流量变现新机遇:https://www.kjdsnews.com/a/1481662.html
短视频企业号开号难?:https://www.kjdsnews.com/a/1481663.html
怎么给领英群组(LinkedIn Group)内的客户批量发消息添加好友?:https://www.kjdsnews.com/a/1481664.html
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
北京丰台区水上乐园哪家好玩?:https://www.vstour.cn/a/366177.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流