簡單創建XML文件和讀取XML文件的方法

//讀取XML文件的方法

        public string GetWebUrl()
        {
            string filepath = Application.StartupPath + "//Appinfo.xml";   //Application.StartupPath表示exe文件所在的位置。
            bool exists = System.IO.File.Exists(filepath);

            if (exists)
            {
                DataSet ds = new DataSet();
                ds.ReadXml(filepath);

                string strNumber = ds.Tables["webInfo"].Rows[0]["url"].ToString();
                return strNumber;
            }
            else
            {
                return "No url!";
            }
        }

 

//創建XML文件的方法

XmlDocument zcdoc = new XmlDocument();
                    string filepath = Application.StartupPath + "//Appinfo.xml";
                    string xmlstr = "<regInfo><webUrl>" + txtWebAddress.Text.Trim() + "</webUrl></regInfo>";
                    zcdoc.LoadXml(xmlstr);
                    zcdoc.Save(filepath);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章