导出数据到xml(自动下载)

来源:互联网 发布:工业用电量数据 指标 编辑:程序博客网 时间:2024/04/29 17:40

           手动拼写xml字符串

        string title = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
        string root = "<Batch>\n";
        string end = "</Batch>\n";

                     ----------------------

            string str = Export2Xml(list);

            byte[] by = System.Text.Encoding.Default.GetBytes(str);
            this.Response.OutputStream.Write(by,0,Convert.ToInt32(by.Length));
            Response.Charset = "gb2312";
            Response.AppendHeader("Content-Disposition", "attachment;filename=us_export.xml");
            Response.ContentType = "text/xml";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            System.IO.StringWriter  tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter (tw);
            Response.Write(tw.ToString());
            tw.Close();
            hw.Close();

            Response.End();


输出到前台。


原创粉丝点击