舞步者

天行健,君子以自强不息;地势坤,君子以厚德载物
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

修改配置文件的函数

Posted on 2006-02-23 13:57  舞步者  阅读(144)  评论(0)    收藏  举报
public static bool WirteConfigurationSetting(string name,string val)
{
XmlDocument doc = new XmlDocument();
doc.Load(ConfigInfoClass.ConfigFileName);
XmlNode root = doc.DocumentElement;
XmlNodeList xnl = doc.SelectNodes(string.Format("configuration/appSettings/add[@key='{0}']",name));
int Num = xnl.Count;
if(Num != 1) return false;
XmlNode node = xnl[0];
node.Attributes["value"].Value = val;
doc.Save(ConfigInfoClass.ConfigFileName);
return true;
}