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?
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("~");
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