我在我的班约10个方法。 在每一个方法我用ConfigurationManager.AppSettings
获得价值形态App.config文件
喜欢
_applicationPort = int.Parse(ConfigurationManager.AppSettings["ApplicationPort"]
我的问题是,我想使这个代码像AnotherPoject.exe.config另一个app.config文件得到的AppSettings。
我在我的班约10个方法。 在每一个方法我用ConfigurationManager.AppSettings
获得价值形态App.config文件
喜欢
_applicationPort = int.Parse(ConfigurationManager.AppSettings["ApplicationPort"]
我的问题是,我想使这个代码像AnotherPoject.exe.config另一个app.config文件得到的AppSettings。
您还可以设置app.config
读取其他文件。 事情是这样的:
<?xml version="1.0"?>
<configuration>
<appSettings file="my\custom\file\path\external.config"/>
</configuration>
和external.config
将有appSettings部分:
<appSettings>
<add key="myKey" value="myValue" />
</appSettings>
请参阅此MSDN ,了解更多信息。
你可以做这样的事情
var fileConfig = ConfigurationManager.OpenExeConfiguration("<filePath>");
int port = int.Parse(fileConfig.AppSettings["PortNumber"].ToString());
您可以通过完成此ConfigurationManager.OpenExeConfiguration
。 这将允许您轻松地打开另一个配置文件。
MSDN文章关于OpenExeConfiguration。