asp.net 页面导出txt

mac2022-06-30  106

protected void Button1_Click1(object sender, EventArgs e)    {        Response.Clear();        Response.BufferOutput = true;        //设定输出的字符集        Response.Charset = "GB2312";        //假定导出的文件名为FileName.doc        Response.AppendHeader("Content-Disposition", "attachment;filename=FileName.doc");        Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");        设置导出文件的格式        Response.ContentType = "application/ms-word";        //关闭ViewState        Repeater1.EnableViewState = false;        System.Globalization.CultureInfo cultureInfo = new System.Globalization.CultureInfo("ZH-CN", true);        System.IO.StringWriter stringWriter = new System.IO.StringWriter(cultureInfo);        System.Web.UI.HtmlTextWriter textWriter = new System.Web.UI.HtmlTextWriter(stringWriter);        Repeater1.RenderControl(textWriter);        Repeater2.RenderControl(textWriter);        把HTML写回浏览器        Response.Write(stringWriter.ToString());        Response.End();     

    }

转载于:https://www.cnblogs.com/sunnysmile/archive/2009/06/22/1508403.html

最新回复(0)