C#如何生成一个XML文件,并保存在硬盘的指定目录下

 1 using  System;
 2 using  System.Collections;
 3 using  System.ComponentModel;
 4 using  System.Data;
 5 using  System.Drawing;
 6 using  System.Web;
 7 using  System.Web.SessionState;
 8 using  System.Web.UI;
 9 using  System.Web.UI.WebControls;
10 using  System.Web.UI.HtmlControls;
11 using  System.IO;
12 namespace  UploadFile
13 {
14    /**//// <summary>
15    /// Summary description for WebForm1.
16    /// </summary>

17    public partial class UploadPage : System.Web.UI.Page
18    {
19        private void Page_Load(object sender, System.EventArgs e)
20        {
21            try
22            {
23                string strXML = Request.QueryString["DefXML"];
24
25                string strFolder = "C:\\UploadFiles\\";
26                if (!System.IO.Directory.Exists(strFolder))
27                {
28                    System.IO.Directory.CreateDirectory(strFolder);
29                }

30                string strFileName = strFolder + DateTime.Now.ToString("yyyy_MM_dd_hh_mm_ss"+ ".xml";
31                FileStream fs = new System.IO.FileStream(strFileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);
32                StreamWriter sw = new System.IO.StreamWriter(fs);
33                sw.WriteLine(strXML);
34                sw.Flush();
35                sw.Close();
36                fs.Close();
37                Response.Write(strXML + "! File Save OK!");
38            }

39            catch (Exception ex)
40            {
41                Response.Write(ex.Message);
42            }

43            // Put user code to initialize the page here
44        }

45
46    //    #region Web Form Designer generated code
47        //override protected void OnInit(EventArgs e)
48    //    {
49    //        //
50    //        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
51    //        //
52    //        InitializeComponent();
53    //        base.OnInit(e);
54    //    }
55
56    //    /// <summary>
57    //    /// Required method for Designer support - do not modify
58    //    /// the contents of this method with the code editor.
59    //    /// </summary>
60    //    private void InitializeComponent()
61    //    {
62    //        this.Load += new System.EventHandler(this.Page_Load);
63    //    }
64    //    #endregion
65    }

66}

67

转载于:https://www.cnblogs.com/wj-wangjun/archive/2008/02/21/1076391.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值