Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the path to the app.config programmatically

Tags:

c#

app-config

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.

like image 951
grenade Avatar asked Apr 26 '10 13:04

grenade


People also ask

Where is app config file located?

A typical location would be: C:\Windows\System32\inetsrv\ApplicationHost. config.

Where is app config file in Visual Studio 2010?

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.

What is app config file in VB NET?

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.


1 Answers

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

like image 130
Fredrik Mörk Avatar answered Oct 10 '22 01:10

Fredrik Mörk