当我正在使用以下代码从服务器下载文件:
Response.AddHeader("Content-Disposition", "attachment; filename=" +
Server.UrlPathEncode(Path.GetFileName(_Filename)));
Run Code Online (Sandbox Code Playgroud)
问题是在文件名中有空格时,使用此代码,服务器会在找到第一个空格时自动拆分!
我希望知道为什么以及解决方案是什么?
我想将数据从DaraGrid导出到Excel文件中.用法语提供这些数据在这里,你是我的方法:
public static void ExportGridView( DataGrid dataGrid, string fileName)
{
HttpResponse m_Response = HttpContext.Current.Response;
m_Response.Clear();
m_Response.AddHeader("content-disposition",
string.Format("attachment;filename={0}", fileName));
m_Response.Charset = "";
m_Response.ContentType = "application/octet-stream"; //"application/vnd.xls";
m_Response.ContentEncoding = Encoding.UTF32;
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
dataGrid.RenderControl(htmlWrite);
m_Response.Write(stringWrite.ToString());
m_Response.End();
}
Run Code Online (Sandbox Code Playgroud)
否则输出不是良好的法语格式
例)
Engagé=>engagé
Société=>Société