在一个位置访问的App.config从二进制不同 [英] Accessing App.config in a location different from the binary

查看:127
本文介绍了在一个位置访问的App.config从二进制不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个.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

参考: http://msdn.microsoft.com/ EN-US /库/ system.configuration.configurationmanager.openexeconfiguration.aspx


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆