gridview转Excel时 ,文件名为乱码的解决方法

来源:互联网 发布:js怎么隐藏span 编辑:程序博客网 时间:2024/05/21 21:43
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" +HttpUtility.UrlEncode("考勤")+ path + ".xls");


彻底解决的方法:
       
string FileName = System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("考勤" + path + ".xls"));
        //HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + System.Convert.ToChar(34) + FileName + System.Convert.ToChar(34));
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "inline;filename=" + System.Convert.ToChar(34) + FileName + System.Convert.ToChar(34));


注意:其中
inline是在线,attachment是(下载)

public static string UrlEncode(string str, System.Text.Encoding e)
    Member of System.Web.HttpUtility

Summary:
Encodes a URL string using the specified encoding object.

Parameters:
e: The System.Text.Encoding object that specifies the encoding scheme.
str: The text to encode.

Returns:
An encoded string.


public sealed class HttpUtility
    Member of System.Web

Summary:
Provides methods for encoding and decoding URLs when processing Web requests. This class cannot be inherited.
 
原创粉丝点击