zoukankan      html  css  js  c++  java
  • Asp.Net导出文件名中文乱码

    Asp.Net导出word为例,Excel等其他文件也一样

    protected void Page_Load(object sender, EventArgs e)
        {string html = “网页html代码”;
            string fileName = "故事.doc";
            DownloadDoc(fileName,html);
        }
        public void DownloadDoc(string fileName, string pageHtml)
        {
            //设置Http的头信息,编码格式  
            HttpContext.Current.Response.Buffer = true;
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Charset = "gb2312";
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            HttpContext.Current.Response.ContentType = "application/ms-word";
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + clFielName(fileName));
            //关闭控件的视图状态  ,如果仍然为true,RenderControl将启用页的跟踪功能,存储与控件有关的跟踪信息
            this.EnableViewState = false;
    
            HttpContext.Current.Response.Write(pageHtml);
            HttpContext.Current.Response.End();
        }
        public string clFielName(string fileName)
        {
            System.Web.HttpContext curContext = System.Web.HttpContext.Current;
            string outputFileName = null;
            string browser = curContext.Request.UserAgent.ToUpper();
            if (browser.Contains("MS") == true && browser.Contains("IE") == true)
            {
                outputFileName = System.Web.HttpUtility.UrlEncode(fileName);
            }
            else if (browser.Contains("FIREFOX") == true)
            {
                outputFileName = """ + fileName + """;
            }
            else
            {
                outputFileName = System.Web.HttpUtility.UrlEncode(fileName);
            }
            return outputFileName;
        }

    判断不同的浏览器,然后编码

  • 相关阅读:
    看起来像一个输入框的input,实际上是有两个input
    Actions类的一些主要方法
    selenium通过WebDriverWait实现ajax测试,实现等页面元素加载完成
    如何判断新打开窗口是否需要切换
    鼠标悬停
    Selenium WebDriver使用IE浏览器
    Element should have been select but was input
    58同城Java面试
    2个线程ABAB或者BABA循环输出
    使多个线程循环输出099099
  • 原文地址:https://www.cnblogs.com/webapi/p/10148555.html
Copyright © 2011-2022 走看看