10

I want to know which *.config file the ConfigurationManager is using. How can I figure that out?

For instance, you could be changing working directories and execute libraries from various paths. I'd love to have a way to display something like "Reading AppSettings from c:\MyApp\app.config" in my Trace.

Larsenal
  • 49,878
  • 43
  • 152
  • 220

1 Answers1

10
System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath
David Morton
  • 16,338
  • 3
  • 63
  • 73
  • 6
    Doesn't work when running in a web app. "exePath must be specified when not running inside a stand alone exe." – mhenry1384 Jul 29 '11 at 18:34
  • When running a web app you need to use System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~").FilePath; – Hylle Feb 27 '19 at 11:39