您的位置:首页 > 其它

.NET 在线生成XML文档,并提供下载

2010-08-31 00:26 417 查看
今天在写自己的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文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: