How-To Geek

How to Add a Configuration File to your Windows Forms application

When you are creating a new Windows Forms application, it isn’t immediately obvious how to get a configuration file for your application. Your application configuration file is supposed to be called executablename.exe.config, and should be in the same directory as your application in order for the .NET framework to automatically use it.

But when you create the configuration file in the \bin\debug directory, it gets overwritten immediately when you do a new build. That’s slightly annoying.

The proper way to add this file is to add new new configuration file called App.config to your project, which Visual Studio will automatically copy and rename to the same name as your executable’s name when you do a build.

There’s a really simple way to do this.. simply go to the File \ Add New Item menu, or hit Ctrl+Shift+A

You’ll notice that it’s already set to App.config for you. Just hit the Open button.

If you look in the Solution Explorer, you will see that the config file is in your project:

Now build your application, and take a look in the \bin\debug\ folder. You’ll see that the configuration file has automatically been generated and named correctly for your executable:

If you change the name of the outputted file, Visual Studio is smart enough to generate the new filename correctly.

Enjoy Configuring!

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 10/17/06

Comments (3)

  1. renuka

    thank you very much really helpful , thanks a lot

  2. Becky

    The screens are different in my Visual Studio version which is 2008… there is no option to Add a File type of Application Config File. I’ve been just adding any type of file to the Project, renaming it, and moving it below the References area, and also being sure it is copied to the project’s debug folder. Why is it missing in VS 2008?

  3. Rohan Patil

    Thanks its very usefull.

More Articles You Might Like

Enter Your Email Here to Get Access for Free:

Go check your email!