As the question title states, I'm saving some application settings (currently just a database path) to the application configuration file. The changes seem to save into the file ok, but when I then try to read the new data I get an empty string. The new data reads in fine if I restart the application, but I do need it to read in without having to restart the app. My config settings class is below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Windows.Forms;
namespace HADDMS_Asset_Management_System
{
public static class ConfigSettings
{
public static bool WriteSetting(string key, string value)
{
try
{
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(key);
}
catch (Exception e)
{
MessageBox.Show("Error writing to configuration settings:\r\n" + e.ToString());
return false;
}
return true;
}
public static string ReadSetting(string key)
{
return ConfigurationManager.AppSettings[key];
}
public static string ReadSetting(int keyIndex)
{
return ConfigurationManager.AppSettings[keyIndex];
}
}
}
Edit: I should add that I am running the application from the release folder.