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.
A typical location would be: C:\Windows\System32\inetsrv\ApplicationHost. config.
Right-click on the project, select Add->New Item..., then select "Application Configuration File" from the list of possible items. Show activity on this post. It would be a template in the templates directory of Visual Studio.
It references the C# project for user management services. Both connect to the same database. The connection string to this database is stored in the app. config file of the VB.NET project. It also contains other user and application level settings.
I usually use AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
. Didn't try it in a Windows Service context though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With