grenade
grenade

Reputation: 32179

Access the path to the app.config programmatically

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.

Upvotes: 7

Views: 1322

Answers (1)

Fredrik Mörk
Fredrik Mörk

Reputation: 158289

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

Upvotes: 9

Related Questions