Click here to Skip to main content
15,611,545 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I have an example from the article.

here is the App.config file:
<?xml version="1.0" encoding="utf-8" ?>
    <add key="Setting1" value="Very" />
    <add key="Setting2" value="Easy" />

here is the console program write.cs:
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace AppSettings
   class Program
     static void ShowConfig()

        // For read access you do not need to call OpenExeConfiguraton
        foreach(string key in ConfigurationManager.AppSettings)
           string value = ConfigurationManager.AppSettings[key];
           Console.WriteLine("Key: {0}, Value: {1}", key, value);

     static void Main(string[] args)


        // Open App.Config of executable
        System.Configuration.Configuration config =

        // Add an Application Setting.
                       DateTime.Now.ToLongTimeString() + " ");

        // Save the changes in App.config file.

        // Force a reload of a changed section.

What I have tried:

I am expecting this ModificationDate shall come up in App.config, but it turns out in write.exe.config file. why did this happen? the new variable can not be added into App.Config directly?
Updated 1-Mar-16 3:48am
ZurdoDev 1-Mar-16 9:33am    
Write.exe.config actually IS your app.config file. It takes the name of the executable.
CHill60 1-Mar-16 9:41am    
That's the solution :)
ZurdoDev 1-Mar-16 9:47am    
I know, but it seemed to easy.

1 solution

As mentioned in the comments, Write.exe.config actually IS your app.config file. It takes the name of the executable.
Share this answer
Sergey Alexandrovich Kryukov 1-Mar-16 10:34am    
5ed, but I'm not sure the inquirer understands that. If one understood the purpose of config, this person would find it questionable, if tho different .EXE file had the same app.config; how the runtime would find it? And would not the mere observation of renamed file in output directory immediately give the idea? :-)
The question is some indication of having no proper understanding of what is the source code and what goes to runtime...

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