请选择 进入手机版 | 继续访问电脑版

马上加入IBC程序猿 各种源码随意下,各种教程随便看! 注册 每日签到 加入编程讨论群

C#教程 ASP.NET教程 C#视频教程程序源码享受不尽 C#技术求助 ASP.NET技术求助

【源码下载】 社群合作 申请版主 程序开发 【远程协助】 每天乐一乐 每日签到 【承接外包项目】 面试-葵花宝典下载

官方一群:

官方二群:

ASP.NET下载中文文件名乱码解决方法

[复制链接]
查看3915 | 回复1 | 2015-9-6 09:26:16 | 显示全部楼层 |阅读模式
转载,代码未经楼主测试

[C#] 纯文本查看 复制代码
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
        { }


C#论坛 www.ibcibc.com IBC编程社区
C#
C#论坛
IBC编程社区
推人落水 | 2015-10-27 13:08:44 | 显示全部楼层
頂一個
*滑块验证:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则