Reputation: 96561
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
.
Upvotes: 8
Views: 3062
Reputation: 351516
Gets the physical path to the configuration file represented by this Configuration object.
Upvotes: 0
Reputation: 887453
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");
Upvotes: 16