.NET 按格式导出txt

效果图

.NET 按格式导出txt_第1张图片

 

后台代码

        private void DownTxt()
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < 50000; i++)
                {
                    sb.Append("测试i=" + i+"\r\n");
                }
                Response.Clear();
                Response.Headers["Content-Disposition"] = "attachment;filename=aaa.txt";//输出文件格式
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //解决乱码问题
                Response.Write(sb.ToString());
            }
            catch (Exception EX)
            {
                throw EX;
            }
        }

你可能感兴趣的:(.NET 按格式导出txt)