国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

使用Linq to XML 修改app.config

2019-11-17 03:20:23
字體:
來源:轉載
供稿:網友

使用Linq to xml 修改app.config

使用其他的方法修改app.config無效。而且修改的是*.vshost.exe.Config,程序運行時正常,關閉之后就還是原來的值。

Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);               configuration.AppSettings.Settings["節(jié)點名稱"].Value ="0";               configuration.Save(ConfigurationSaveMode.Modified);   
其他方法(測試無效)

直接上代碼。

 //獲取config路徑                string path = System.Windows.Forms.application.ExecutablePath + ".config";                XDocument doc = XDocument.Load(path);                //查找所有節(jié)點                IEnumerable<XElement> element = doc.Element("configuration").Element("appSettings").Elements();                //遍歷節(jié)點                foreach (XElement item in element)                {                    if (item.Attribute("key") != null && item.Attribute("key").Value == "節(jié)點名稱")                    {                        if (item.Attribute("value") != null)                        {                            item.Attribute("value").SetValue(DateTime.Now.ToString("d"));                        }                    }                }                //保存                doc.Save(path);


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 谷城县| 昆山市| 长沙市| 安义县| 开封市| 迭部县| 阿勒泰市| 上饶县| 海门市| 柳林县| 临江市| 凌源市| 明水县| 边坝县| 自贡市| 峡江县| 清流县| 皋兰县| 台山市| 兰坪| 迭部县| 曲周县| 青冈县| 开原市| 林州市| 开平市| 界首市| 福鼎市| 长兴县| 鄂尔多斯市| 神农架林区| 开平市| 临城县| 光泽县| 上林县| 社会| 临漳县| 日土县| 贵州省| 贡山| 陆丰市|