For some reason my last project had no problems setting and reading things in my config file (appname.exe.config) but for some reason in a new app I can write to the file but never read anything but blanks. Here's what I am doing. The config file automagically appears in the debug folder (I didn't add new to get one).
I have "using System.Configuration" in the header.
The class starts this way:
I checked and the sKey value is exactly the same in both the save and get functions (I use a single constant to send to both so I shouldn't even have had to check but what the heck.) The setting shows up in the <appname>.exe.config file
but when I read dbLocation I get nothing. I must be missing something in this app (though I copied the code from a working app so it shouldn't be).
If no ideas then is there some other way of setting an application scope variable during runtime and being able to read/change it later? the MS settings works fine on a user scope but is read only on an application scope so that's no good to me.
I have "using System.Configuration" in the header.
The class starts this way:
utills class:
public static class Utils
{
public static bool SaveKeyValue(string key, string value)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);
config.AppSettings.Settings.Remove(key);
config.AppSettings.Settings.Add(key, value);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
return true;
}
public static string GetKeyValue(string sKey)
{
MessageBox.Show("Key: " + sKey);
string value = ConfigurationManager.AppSettings[sKey];
return value;
}
I checked and the sKey value is exactly the same in both the save and get functions (I use a single constant to send to both so I shouldn't even have had to check but what the heck.) The setting shows up in the <appname>.exe.config file
XML:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="dbLocation" value="C:\ProgramData\PatPOS\PatPOS.sqlite3" />
</appSettings>
</configuration>
but when I read dbLocation I get nothing. I must be missing something in this app (though I copied the code from a working app so it shouldn't be).
If no ideas then is there some other way of setting an application scope variable during runtime and being able to read/change it later? the MS settings works fine on a user scope but is read only on an application scope so that's no good to me.