Is there any way that I could specify at runtime the configuration file I would like to use (other than App.config)? For example I would like to read a first argument from a command line that will be a path to the application's config and I would like my application to refer to it when I use ConfigurationManager.AppSettings (It's probably impossible but still it's worth asking).
I did find this piece of code:
System.Configuration.Configuration config
= ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.File = myRuntimeConfigFilePath;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
It works, but it overrides the original App.config's AppSettings section and my application isn't supposed to write anything.
There is a global configuration file for all sites in a given machine which is called Machine. config. This file is typically found in the C:\WINDOWS\Microsoft.NET\Framework\v2. 0.50727\CONFIG directory.
Configuration files are commonplace within . NET and are often used to hold application-specific runtime configuration settings, connection strings or web service bindings.
I found this and it works. "path" is a path to configuration file.
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With