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

首頁 > 編程 > C# > 正文

使用linq to xml修改app.config示例(linq讀取xml)

2020-01-24 02:47:17
字體:
來源:轉載
供稿:網友

復制代碼 代碼如下:

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ā)表
主站蜘蛛池模板: 蕉岭县| 台州市| 寿光市| 万山特区| 麻江县| 公安县| 高唐县| 灵璧县| 孝义市| 丘北县| 禄劝| 和顺县| 陈巴尔虎旗| 苍山县| 浦县| 唐河县| 太湖县| 枣庄市| 达拉特旗| 志丹县| 商水县| 子长县| 曲沃县| 塘沽区| 通州区| 汝城县| 桂平市| 徐闻县| 揭西县| 古浪县| 庄浪县| 电白县| 霍山县| 靖州| 贵港市| 兴城市| 建德市| 河间市| 通江县| 旬阳县| 通江县|