System.COnfiguration in C#2.0

I tried to add a new key value pair in app.setting

System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);config.AppSettings.Settings.Add("ModificationDate",DateTime.Now.ToLongTimeString());

config.Save(ConfigurationSaveMode.Modified,true);

config.SaveAs("New");

// Force a reload of a changed section.

ConfigurationManager.RefreshSection("appSettings");

But i can't see the change being reflected in the file....

[1273 byte] By [vibha504] at [2007-12-23]
# 1

Hi,

You need to change how you open the configuration reference to (otherwise you only change the appsettings that the app holds in memory)

Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);

This example works:

Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
// Create a new AppSettings key-value pair entry:
config.AppSettings.Settings.Add("NewKey", "New Value");
// Save the changes back to the original configuration file:
config.Save();

Cheers!

SalvaPatuel at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
Thanks..it worked
vibha504 at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
IS there any method in ConfigurationManager.OpenExeConfiguration ...by which we can update keyvalue pair in config file...
vibha504 at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 4

Hi,

Use

config.AppSettings.Settings["YourKey"].Value = "YourValue";

Regards

SalvaPatuel at 2007-8-30 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified