Skip to main content

Adding a Configuration File

Rather than hard coding connection information into the application, you can configure your application to load the information dynamically from a configuration file. To add a configuration file to your project do the following:

  1. Add a reference to System.Configuration to your project.

  2. Add the following using directive:

    using System.Configuration;
  3. Click Project –> Add New Item.

  4. In the Add New Item dialog, click Application Configuration File. Enter a name for the file. Note that the name must have the following form: <Application Name>.config. For example, the name of the configuration file for the PhonebookObj application is PhonebookObj.exe.config.

  5. In the property inspector, change the value of the configuration file's Copy to Output Directory build action to Copy always.

FeedbackOpens in a new tab