This is my first time using an XML config file. In the solution explorer I right click, add, new item, application config. file.
I then edited the file to read…
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Key1" value="1000" />
</appSettings>
</configuration>
…and tried to access it with…
Int32.Parse(ConfigurationManager.AppSettings.Get("Key1"));
…but it says that the parameter is null. I looked at just ConfigurationManager.AppSettings and it’s AllKeys property has dimension 0.
What am I doing wrong?
Thanks!
Right-click on your project, choose Properties>Settings tab and edit your settings there because the config file is not the only place these values are stored at.
In your code use
Settings.Default.MySettingto access the settings.You’ll need to add
using MyProjectName.Properties;to your using statements in order to access the settings this way or you’ll have to fully qualify it asMyProjectName.Properties.Settings.Default.MySetting…