【发布时间】:2011-02-06 17:19:36
【问题描述】:
有没有办法从类库中找到当前应用程序的配置文件的名称(和路径)?
例如在 Web 应用程序中,这将是 web.config,在 Windows 应用程序或服务中,这将是 myapp.exe.config。
【问题讨论】:
标签: .net configuration web-config app-config
有没有办法从类库中找到当前应用程序的配置文件的名称(和路径)?
例如在 Web 应用程序中,这将是 web.config,在 Windows 应用程序或服务中,这将是 myapp.exe.config。
【问题讨论】:
标签: .net configuration web-config app-config
试试这个:
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
如果这不起作用,请添加对 System.Web 和 System.Configuration 的引用,然后试试这个:
if(HttpRuntime.AppDomainAppVirtualPath == null)
return ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).FilePath;
else
return VirtualPathUtility.ToAbsolute("~/Web.config");
【讨论】:
获取此配置对象表示的配置文件的物理路径。
【讨论】: