导出信息到txt文件

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();
}

posted @ 2018-08-01 17:18  木水z  阅读(556)  评论(1)    收藏  举报