7

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.

1 Answer 1

9

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

Sign up to request clarification or add additional context in comments.

1 Comment

Oohh, I didn't know that. Sorry. :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.