从程序集中查找应用程序配置文件

时间:2011-07-13 09:45:22

标签: c# config

我正在使用Nini在整个应用中阅读配置。我在程序集中遇到问题,我想读取主应用程序配置文件(无论是web.config还是app.config)。

这是标准方式:

private static IConfigSource source = new DotNetConfigSource(DotNetConfigSource.GetFullConfigPath());

程序集的问题是DotNetConfigSource.GetFullConfigPath()返回“assembly.dll.config”,而不是“app.exe.config”或“web.config”。

做什么,该做什么?

1 个答案:

答案 0 :(得分:1)

System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

string configPath = config.FilePath;

private static IConfigSource source = new DotNetConfigSource(configPath);

试试。