This is a desktop application created with .NET Framework in Windows Forms.
I want to create a way to overwrite app.config->appSettings values.
When the project init it calls a function that get params from a database matching appName.
This is the function:
private void LoadAppConfigs()
{
var appConfigs = Connection.GetAppConfigs();
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
foreach (var c in appConfigs)
{
config.AppSettings.Settings[c.Key].Value = c.Value;
}
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
}
It works, but this implies writing to disk (modifying app.config
) which is problematic because users doesn't have access to write to the disk.
Is there a way to modify AppSettings
at runtime without writing to disk?
Is there another way I can use to achieve this?