Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get filename of current configuration file

I'd think this would be simple, but I can't find an answer.

I'm using remoting and I want to store the RemotingConfiguration in the app.config. When I call RemotingConfiguration.Configure I have to supply the filename where the remoting information resides. So... I need to know the name of the current configuration file.

Currently I'm using this:

System.Reflection.Assembly.GetExecutingAssembly().Location + ".config" 

But this only works for windows applications, not for web applications.

Isn't there any class that can supply me with the name of the current config file?

like image 746
comecme Avatar asked May 04 '11 19:05

comecme


2 Answers

Try AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

https://docs.microsoft.com/en-us/dotnet/api/system.appdomainsetup.configurationfile

like image 193
Paul Alexander Avatar answered Sep 23 '22 13:09

Paul Alexander


using System.Configuration; Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); Console.WriteLine(config.FilePath); 

In the odd case that you have separate configuration files for specific local or roaming users, you can locate those as well using the correct ConfigurationUserLevel. For web applications, use

WebConfigurationManager.OpenWebConfiguration("~"); 
like image 39
Michael Edenfield Avatar answered Sep 20 '22 13:09

Michael Edenfield