Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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>

-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.
Posted
Comments
[no name] 7-Aug-12 22:31pm    
http://support.microsoft.com/kb/815786
Remedylane 8-Aug-12 8:15am    
I'll try it as i get home, thanks :)
Santhosh Kumar Jayaraman 7-Aug-12 22:36pm    
where you added this config file?In your start up project?
Remedylane 8-Aug-12 8:02am    
Yes, i only have one project anyway, and its form application.

If you having multiple project in your solution, and say the startup project is webapplication and you having the below code

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


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.
 
Share this answer
 
Comments
Remedylane 8-Aug-12 8:14am    
I only have one project in my solution and i added appconfig to that project.
I found the problem, the problem was my config file wasn't in the same folder with my exe and it should be named as ApplicationName.ApplicationType.config like myprogram.exe.config

Thanks for the link Wes Aday!
 
Share this answer
 
Comments
[no name] 8-Aug-12 14:07pm    
You're welcome. Glad it helped.
Try with the following:

C#
System.Configuration.ConfigurationSettings.AppSettings["openwin"].ToString();
OR
(string)System.Configuration.ConfigurationSettings.AppSettings.Get("openwin");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900