在一个位置访问的App.config从二进制不同 [英] Accessing App.config in a location different from the binary
问题描述
在一个.NET赢控制台应用程序,我想访问一个App.config文件从控制台应用程序二进制文件不同的位置。例如,哪有C:\bin\Text.exe从C得到它的设置:\Test.exe.config
使用System.Configuration;
配置配置=
ConfigurationManager.OpenExeConfiguration(C:\Test.exe);
然后,您可以从配置实例访问的应用程序设置,连接字符串,等等。在假定该配置文件的格式正确的,你的应用程序有读权限的目录。注意路径为的不的C:\Test.exe.config的方法查找与您指定的文件关联的配置文件。如果指定C:\Test.exe.config它会寻找C:\Test.exe.config.config有点儿跛,但可以理解的,我猜
$ B这里$ b
In a .NET Win console application, I would like to access an App.config file in a location different from the console application binary. For example, how can C:\bin\Text.exe get its settings from C:\Test.exe.config?
using System.Configuration;
Configuration config =
ConfigurationManager.OpenExeConfiguration("C:\Test.exe");
You can then access the app settings, connection strings, etc from the config instance. This assumes of course that the config file is properly formatted and your app has read access to the directory. Notice the path is not "C:\Test.exe.config" The method looks for a config file associated with the file you specify. If you specify "C:\Test.exe.config" it will look for "C:\Test.exe.config.config" Kinda lame, but understandable, I guess.
Reference here: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.openexeconfiguration.aspx
这篇关于在一个位置访问的App.config从二进制不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!