Access the app.config software path

I am looking for a way to programmatically get the path to the app.config file from a Windows service executable. The build process changes App.config to program-name.exe.config , and I could do something like:

 var configFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "program-name.exe.config"); 

However, I am looking for a way to get the name of the configuration file at runtime, which does not require hard-coding the exe name in the application. The ConfigurationManager has some way to do this, so this should be possible.

+7
c # app-config
source share
1 answer

I usually use AppDomain.CurrentDomain.SetupInformation.ConfigurationFile . However, do not try to use it in the context of a Windows service.

+9
source share

All Articles