How to use application config file in C#?

Posted by badpanda on Stack Overflow See other posts from Stack Overflow or by badpanda
Published on 2010-06-08T17:48:11Z Indexed on 2010/06/08 17:52 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

I am trying to use a config file in my C# console application. I created the file within the project by going New --> Application Configuration File, and naming it myProjectName.config. My config file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="SSDirectory" value="D:\Documents and Settings\****\MyDocuments\****" />
</appSettings>
</configuration>

The code to access it looks like this:

private FileValidateUtil()
    {
        sSDirFilePath = ConfigurationSettings.AppSettings["SSDirectory"];
        if (sSDirFilePath == null)
            Console.WriteLine("config file not reading in.");
    }

Can anyone lend a hint as to why this is not working? (I am getting the error message.)

Thanks!!

badPanda

© Stack Overflow or respective owner

Related posts about c#

Related posts about file