static void Main(string[] args)
{
UpdateAppSettings("abc", "value1000");
ConfigurationManager.RefreshSection("appsettings");
Console.WriteLine(ConfigurationManager.AppSettings["abc"]);
}
static void UpdateAppSettings(String KeyName, String KeyValue)
{
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
foreach(XmlElement xElement in XmlDoc.DocumentElement)
{
if(xElement.Name == "appSettings")
{
foreach(XmlNode xNode in xElement.ChildNodes)
{
if(xNode.Attributes[0].Value == KeyName)
{
xNode.Attributes[1].Value = KeyValue;
}
}
}
}
XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
}
Monday, May 11, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment