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.Sett ings///////
//get the key from Properties.Sett ings
string myPropertiesSet ting = (string)Propert ies.Settings.De fault["myKey"];
//This line seems to only set the value in memory and not in the file.
Properties.Sett ings.Default["myKey"] = "myNewValue ";
//myPropertiesSet ting will now be equal to "myNewValue "
myPropertiesSet ting = (string)Propert ies.Settings.De fault["myKey"];
//things look good, except when I restart the application the new value
//was not stored in the settings.cs file.
//////Using ConfigurationMa nager.AppSettin gs///////
NameValueCollec tion appSettings = ConfigurationMa nager.AppSettin gs;
//get the key from ConfigurationMa nager.AppSettin gs
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.Sett ings///////
//get the key from Properties.Sett ings
string myPropertiesSet ting = (string)Propert ies.Settings.De fault["myKey"];
//This line seems to only set the value in memory and not in the file.
Properties.Sett ings.Default["myKey"] = "myNewValue ";
//myPropertiesSet ting will now be equal to "myNewValue "
myPropertiesSet ting = (string)Propert ies.Settings.De fault["myKey"];
//things look good, except when I restart the application the new value
//was not stored in the settings.cs file.
//////Using ConfigurationMa nager.AppSettin gs///////
NameValueCollec tion appSettings = ConfigurationMa nager.AppSettin gs;
//get the key from ConfigurationMa nager.AppSettin gs
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
Comment