Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

How to properly use custom config file in C# console application

$
0
0

I am writing a simple console application that will, in the end, open a web browser page.
I want the browser name to be saved in an external configuration file, so that the user can manually change it to their favourite. (Though I am open to a different approach, this was the one deemed best for the uses of the application).

However, I cannot use the App.config file, as it is located in the application folder, which cannot be accessed by non-admin users. (Moving the application folder is not an option, as it will be installed under Program Files).

Therefore I would like to have the application use another .config file, located in the user's Documents (or any other accessible folder), though I haven't found any "canonical" way to tell my application to look for that file, instead of the default App.config, and still be able to use the ConfigurationManager like this:

browser = ConfigurationManager.AppSettings.Get("browser");

Is there a way to tell my application to load a different .config file, or should I open it as a normal text file and handle the parsing?

Edit: I am using .NET Core 3.1 and VisualStudio 2019


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>