现在的位置: 首页 > 综合 > 正文

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

2013年11月15日 ⁄ 综合 ⁄ 共 1004字 ⁄ 字号 评论关闭
        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.
 

抱歉!评论已关闭.