使用linq to xml修改app.config示例(linq讀取xml)
更新時間:2014年02月25日 10:53:45 作者:
這篇文章主要介紹了使用linq to xml修改app.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);
相關(guān)文章
C#實現(xiàn)根據(jù)實體類自動創(chuàng)建數(shù)據(jù)庫表
本文主要介紹了C#通過自定義特性實現(xiàn)根據(jù)實體類自動創(chuàng)建數(shù)據(jù)庫表的方法。具有很好的參考價值,需要的朋友一起來看下吧2016-12-12
C#中Override關(guān)鍵字和New關(guān)鍵字的用法詳解
這篇文章主要介紹了C#中Override關(guān)鍵字和New關(guān)鍵字的用法,需要的朋友可以參考下2016-01-01

