Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET own configuration file

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.

like image 693
agnieszka Avatar asked Feb 10 '09 11:02

agnieszka


People also ask

Where is .NET configuration file?

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.

What is .NET config file?

Configuration files are commonplace within . NET and are often used to hold application-specific runtime configuration settings, connection strings or web service bindings.


1 Answers

I found this and it works. "path" is a path to configuration file.

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
like image 168
agnieszka Avatar answered Sep 22 '22 21:09

agnieszka