tags:

views:

132

answers:

1

I am looking for a way to programmatically obtain the path to the app.config file from within 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'm looking for some way of obtaining the config file name at runtime that doesn't involve hard coding the exe name into the application. ConfigurationManager has some way of doing it, so it must be possible.

+5  A: 

I usually use AppDomain.CurrentDomain.SetupInformation.ConfigurationFile. Didn't try it in a Windows Service context though.

Fredrik Mörk
That is perfect.
grenade
<-- Accept answer
Filip Ekberg
@Filip Ekberg: In six minutes, the SO gods will make that possible...
grenade
Oohh, I didn't know that. Sorry. :)
Filip Ekberg