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
.
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
.
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");
Gets the physical path to the configuration file represented by this Configuration object.