C#导出txt文件

//导成txt
Response.Clear();
            Response.Buffer = false;
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + Server.UrlEncode(fileName) + ".txt");
            Response.ContentType = "text/plain";
            this.EnableViewState = false;
            Response.Write(sb.ToString());
            Response.End();

//导成excel
Response.Clear();
            Response.Buffer = false;
            Response.Charset = "GB2312";
            //Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.AppendHeader("Content-Disposition", "attachment;filename=aa.txt");
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
            //Response.ContentType = "application/ms-excel";
            Response.ContentType = "text/plain";
            this.EnableViewState = false;
       //    System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            //System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            //this.GridView1.RenderControl(oHtmlTextWriter);
            Response.Write("sdfasdfasdfasdfasdfasdfasdfasdfadf");
            Response.End();

posted on 2007-12-02 22:50  lei1217  阅读(2147)  评论(0编辑  收藏  举报

导航