J
Jon
Hello,
I have tried to use the app.config and settings.cs files to store my data
(which I want to be user changeable at runtime). I can write to (what I
assume is an object in memory) and it does seem to work...however, once the
application is closed and reopened the changes are lost. How do I persist
the information?
Here is some sample code using both methods:
//////Using Properties.Settings///////
//get the key from Properties.Settings
string myPropertiesSetting = (string)Properties.Settings.Default["myKey"];
//This line seems to only set the value in memory and not in the file.
Properties.Settings.Default["myKey"] = "myNewValue";
//myPropertiesSetting will now be equal to "myNewValue"
myPropertiesSetting = (string)Properties.Settings.Default["myKey"];
//things look good, except when I restart the application the new value
//was not stored in the settings.cs file.
//////Using ConfigurationManager.AppSettings///////
NameValueCollection appSettings = ConfigurationManager.AppSettings;
//get the key from ConfigurationManager.AppSettings
String myAppSetting = appSettings["myKey"];
//This line seems to only set the value in memory and not in the file.
appSettings["myKey"] = "myNewValue";
//appSettings will now be equal to "myNewValue"
myAppSetting = appSettings["myKey"];
//things look good, except when I restart the application the new value
//was not stored in the app.config file.
Thanks,
Jon
I have tried to use the app.config and settings.cs files to store my data
(which I want to be user changeable at runtime). I can write to (what I
assume is an object in memory) and it does seem to work...however, once the
application is closed and reopened the changes are lost. How do I persist
the information?
Here is some sample code using both methods:
//////Using Properties.Settings///////
//get the key from Properties.Settings
string myPropertiesSetting = (string)Properties.Settings.Default["myKey"];
//This line seems to only set the value in memory and not in the file.
Properties.Settings.Default["myKey"] = "myNewValue";
//myPropertiesSetting will now be equal to "myNewValue"
myPropertiesSetting = (string)Properties.Settings.Default["myKey"];
//things look good, except when I restart the application the new value
//was not stored in the settings.cs file.
//////Using ConfigurationManager.AppSettings///////
NameValueCollection appSettings = ConfigurationManager.AppSettings;
//get the key from ConfigurationManager.AppSettings
String myAppSetting = appSettings["myKey"];
//This line seems to only set the value in memory and not in the file.
appSettings["myKey"] = "myNewValue";
//appSettings will now be equal to "myNewValue"
myAppSetting = appSettings["myKey"];
//things look good, except when I restart the application the new value
//was not stored in the app.config file.
Thanks,
Jon