Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the Config File location via ConfigurationManager?

How to find the Config File location via ConfigurationManager?

I have the ConfigurationManager class in code and I'm debugging it. I'd like to know to which config file it's pointing to (web.config or app.config, etc).

Is there any property or method on the ConfigurationManager that can help with this?

like image 569
The Light Avatar asked Jan 10 '23 12:01

The Light


1 Answers

The configuration file itself is represented by Configuration object. To get this object, run this:

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

Then you can view the file path via config.FilePath.

Update. As pointed out by Schadensbegrenzer for web application you will need another code to load the config file:

Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
like image 170
Andrei Avatar answered Jan 19 '23 00:01

Andrei