Parsing settings in app.config and changing a value

rickmmrr

Newcomer
Joined
Oct 26, 2006
Messages
2
Hi All,

I need to be able to parse the settings in app.config and change some of them.
Then have .NET persisit the changes back to the user.config file since the properties I want to change are user scope. Below is the approach I am taking.

// Get the properties object
Properties.Settings appSettings = ProgramName.Properties.Settings.Default;

// Get the properties collection
SettingsPropertyCollection SettingsCollection = ProgramName.Properties.Settings.Default.Properties;

// get a couple of property objects from the collection
System.Configuration.SettingsProperty Day = zeusSettingsCollection["The_Day"];
System.Configuration.SettingsProperty Year = zeusSettingsCollection["The_Year"];

// change the values
Day.DefaultValue = "Set in Program";
Year.DefaultValue = "Set in Program";

// save the changes
appSettings.Save();

This is not working.

Thanks in advance.
 
Solved

All I had to do was this

ProgramName.Properties.Settings.Default[Key] = Value;
ProgramName.Properties.Settings.Default.Save();
 
Back
Top