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.
彻底解决的方法:
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.
本文介绍了一种解决导出Excel文件时文件名中文显示乱码的问题的方法。通过使用HttpUtility.UrlEncode方法结合UTF-8编码,确保了含有中文字符的文件名能够正确显示。
2162

被折叠的 条评论
为什么被折叠?



