如何访问app.config的appsettings键值。 [英] How to access a app.config's appsettings key value.
问题描述
在我的应用程序中,我有1个类库项目和1个app.config文件。现在我想访问app.config的应用程序设置键值..eg。
Hi,
In my application I have 1 class library project and 1 app.config file.Now I want to access the app.config's app settings key value.eg.
<add key="test" value="Hi" />
现在我正在写
now I am writing
String str=System.Configuration.ConfigurationManager.Appsetting["test"].toString();
在一个类的方法之一。
但它givi字符串中的值为null。
任何人都可以帮助我如何访问它。
我的要求是我必须放一个配置文件中的文件夹路径,我必须从我的应用程序中读取它。
In one of the method of a class.
but it giving value null in the string.
can any one help me out how to access it.
My requirement is I have to put a folder path in the config file and I have to read it from my application.
推荐答案
试试这段代码,
try this code,
string str = new AppSettingsReader().GetValue("test", typeof(System.String)).ToString();
希望它有所帮助,
标记为回答它是否对你有帮助
并且不要忘记投票..
谢谢
hope it helps,
mark this as answer if it helps you
and dont' forget to vote ..
thanks
这篇关于如何访问app.config的appsettings键值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!