本文介绍了无法从appconfig获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.我正在尝试从我的appconfig文件中获取价值,但我做不到.到目前为止,这是我做过的事情:

-右键单击添加了appconfig到项目-添加-新项目-应用程序配置文件
-创建一个appSettings节点并向其添加键和值:

Hello. I''m trying to get value from my appconfig file but i can''t. Here is what i''ve done so far:

-Added appconfig by right click to project-add-new item-Application Configuration File
-Created an appSettings node and added a key and value to it:

<configuration>
  <appSettings>
    <add key="openwin" value="false"/>
  </appSettings>
</configuration>


-添加了System.Configuration作为参考
-我在程序中的密钥的调用值:


-Added System.Configuration as Referance
-Called value of my key in program:

 Dim appValue As String
appValue = System.Configuration.ConfigurationManager.AppSettings("openwin")
MsgBox(appValue)



这应该给我一个假"值,但不是,它只是给我一个无".



This should give me the "false" value but it doesn''t, it simply giving "Nothing" to me.

推荐答案

<add key="openwin" value="false" />



数据访问层(DAL)中的[类库项目]意味着您不必在启动项目中添加它,例如在此将其作为Web应用程序的web.config文件添加.



in Data Access Layer (DAL)[class library project] means that doesn''t make any sense you have to add that in startup project say here as webapplication''s web.config file.



System.Configuration.ConfigurationSettings.AppSettings["openwin"].ToString();
OR
(string)System.Configuration.ConfigurationSettings.AppSettings.Get("openwin");


这篇关于无法从appconfig获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 18:52