Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the name of the current config file

Is there a way to find the name (and path) of the current application's config file from inside a class library?

E.g. in a web app this would be web.config, in a windows app or service this would be myapp.exe.config.

like image 456
M4N Avatar asked Apr 11 '10 14:04

M4N


People also ask

How do I find my config file?

Configuration files are normally saved in the Settings folder inside the My Documents\Source Insight folder.

What is the name of the configuration file?

The master server configuration file is /etc/named. conf. The configuration file contains a list of domain names and the file names containing host information. See The named.

Where is .NET config file?

The Machine. config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ directory.


1 Answers

Try this:

AppDomain.CurrentDomain.SetupInformation.ConfigurationFile

If that doesn't work, add references to System.Web and System.Configuration, then try this:

if(HttpRuntime.AppDomainAppVirtualPath  == null) 
    return ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
else
    return VirtualPathUtility.ToAbsolute("~/Web.config");
like image 87
SLaks Avatar answered Sep 21 '22 06:09

SLaks