码迷,mamicode.com
首页 > 其他好文 > 详细

导出信息到txt文件

时间:2018-08-01 18:24:02      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:encode   编码   chm   port   分享   char   附件   fir   ext   

protected void btnExportErrorInfo_Click(object sender, EventArgs e)
{
string strFileName = "错误信息";
string ExportFileName = string.Empty;
HttpContext curContext = HttpContext.Current;
if (!string.IsNullOrEmpty(strFileName)) { ExportFileName = strFileName; }
//火狐浏览器文件名中文显示
if (curContext.Request.UserAgent.Contains("Firefox"))
{
ExportFileName = ExportFileName + ".txt";
}
else
{
ExportFileName = HttpUtility.UrlEncode(ExportFileName + ".txt", Encoding.UTF8);
}
// 设置编码和附件格式
curContext.Response.ContentType = "application/octet-stream";
curContext.Response.ContentEncoding = Encoding.UTF8;
curContext.Response.Charset = "";
curContext.Response.AppendHeader("Content-Disposition",
"attachment;filename=" + ExportFileName);

string ErrorInfo = "博客园是一个面向开发者的知识分享社区。自创建以来,博客园一直致力并专注于为开发者打造一个纯净的技术交流社区,推动并帮助开发者通过互联网分享知识!";
byte[] data = System.Text.Encoding.Default.GetBytes(ErrorInfo);
curContext.Response.BinaryWrite(data);
curContext.Response.End();
Dispose();
}

导出信息到txt文件

标签:encode   编码   chm   port   分享   char   附件   fir   ext   

原文地址:https://www.cnblogs.com/Let-Fly/p/9402449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!