2011-07-13 44 views
0

我正在使用Nini來讀取整個應用程序中的配置。我遇到了一個問題,我想讀取主應用程序配置文件(無論是web.config還是app.config)。從程序集中查找應用程序配置文件

這是標準的方式:

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

在組件的情況下的問題是,DotNetConfigSource.GetFullConfigPath()返回 「assembly.dll.config」,而不是 「app.exe.config」 或「web.config中」。

怎麼辦,該怎麼辦?

+0

你受妮妮限制嗎?你可以使用System的ConfigurationManager類嗎? – sll

回答

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

string configPath = config.FilePath; 

private static IConfigSource source = new DotNetConfigSource(configPath); 

試試看。