zoukankan      html  css  js  c++  java
  • .NET 在线生成XML文档,并提供下载

    今天在写自己的CMS系统时,需要生成一个网站有KEY,其中一种方法就是让客户把生成的KEY直接下载后放到网站根目录下,这样主要是方便一些内网的网站。
    那怎样动态生成XML文档并提供下载呢?其他这种原理和生成EXECL一样。代码如下:
         int insertID=3;
         string domain="www.w17x.com";
         string enddate="2009-12-1";
         string Dcode="xlxcn";

                       string xml = "<key>\r\n" +
                          @"<webid>" + insertID.ToString() + "</webid>\r\n" +
                          @"<domain>" + domain + "</domain>\r\n" +
                          @"<enddate>" + enddate + "</enddate>\r\n" +
                          @"<code>" + Dcode + "</code>\r\n" +
                          @"</key>";

                        Response.Clear();
                        Response.Buffer = true;
                        //Response.Charset = "UTF8";
                        Response.AppendHeader("Content-Disposition", "attachment;filename=key.xml");
                        Response.ContentEncoding = System.Text.Encoding.UTF8;

                        Response.ContentType = "application/text";
                        System.IO.StringWriter ostringwriter = new System.IO.StringWriter();
                        System.Web.UI.HtmlTextWriter ohtmltextwriter = new HtmlTextWriter(ostringwriter);

                        Response.Write(xml);
                        Response.End();

    此时下载的文件就是key.xml为文件名的一个XML文件。

  • 相关阅读:
    bzoj3675 [Apio2014]序列分割
    bzoj3206 [Apio2013]道路费用
    bzoj3205 [Apio2013]机器人
    bzoj4241 历史研究
    bzoj2821 作诗(Poetize)
    bzoj2724 [Violet 6]蒲公英
    bzoj2811 [Apio2012]Guard
    bzoj2809 [Apio2012]dispatching
    PHP 文字,图片水印,缩略图,裁切成小图(大小变小)
    PHP文件下载方式
  • 原文地址:https://www.cnblogs.com/xiaofengfeng/p/1813146.html
Copyright © 2011-2022 走看看