欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2014年02月25日 10:53:45   作者:  
這篇文章主要介紹了使用linq to xml修改app.config示例,需要的朋友可以參考下

復(fù)制代碼 代碼如下:

Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
configuration.AppSettings.Settings["節(jié)點(diǎn)名稱"].Value ="0"; 
configuration.Save(ConfigurationSaveMode.Modified);  

復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評(píng)論