need help with reading from app config file

  • Thread starter Thread starter comic_rage
  • Start date Start date
C

comic_rage

Hi,

I am trying to read from my application config file and keep getting
null.

Here is my config file


My application is called SampleApp.exe

I named the config file: SampleApp.exe.config


Inside the config file


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="key1" value = "test1"/>
</appSettings>
</configuration>


In my C# code, I have the following

string strTest1 =
System.Configuration.ConfigurationSettings.AppSettings["key1"];

I keep getting null value for strTest1.

I tried placing the SampleApp.exe.config inside the debug bin folder. I
also tried creating a shortcut of the config and placing that shortcut
inside the bin/debug folder, but the same results.


Any help is appreciated.

Thanks,

Rage
 
comic_rage,
When you add an app.config file to your PROJECT, at build time this is
converted to "yourappname.exe.config" and it is deposited right next to the
built executable in either the debug or the release folder, depending on the
build type.
Whatever settings you put into it in design mode in the IDE will be
persisted to the "built" version of the file.
When an application EXE starts, it checks to see if there is a corresponding
..config file, loads and processes it.
You do NOT need to "name" the config file. Leave it as "app.config" in your
project tree and it will be taken care of during the buiild.

Hope that helps!
Peter
 
Back
Top