当前位置:编程学习 > C#/ASP.NET >>

System.Text.Encoding.UTF8; 出现乱码

我做的功能是导出Excel
代码如下
protected void Button1_Click(object sender, EventArgs e)
    {
        string Year = System.DateTime.Now.Year.ToString();
        string Month = System.DateTime.Now.Month.ToString();
        string Day = System.DateTime.Now.Day.ToString();
        string DateString = Year + "-" + Month + "-" + Day;

        ExportToExcel("application/ms-excel", DateString + ".xls");
    }
    public void ExportToExcel(string FileType, string FileName)
    {
        Response.Charset = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
        //System.Text.Encoding.UTF8;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8).ToString());
        Response.ContentType = FileType;
        this.EnableViewState = false;
        StringWriter tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);
        MedicineList.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }

一般的都不会出错  今天突然运行处一条乱码数据  求解  是因为什么 UTF8 GB2312 乱码 --------------------编程问答-------------------- 之前也出现过,把你的文档向下兼容保存一下 --------------------编程问答-------------------- 除非不得已,否则不要使用gb2312。
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,