首页 > 其他 > 详细

导出信息到txt文件

时间:2018-08-01 17:32:51      阅读:159      评论:0      收藏:0      [点我收藏+]

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文件

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!