Create app config file if doesn't exist C#

Viewed 19620

When I try to open my app config file by

ConfigurationManager.OpenExeConfiguration(filePath);

it returns an exception, because there is no file. But I need to create this file in this case. But as I know, config file create by adding at VS like How to: Add an Application Configuration File to a C# Project

So, how to create this file in other way?

6 Answers

For those who are looking the answer in 2022, app.config will be created automatically if you will change the .NET Target Framework in Project properties

To add an application configuration file to a C# project

On the menu bar, choose Project > Add New Item.*

The Add New Item dialog box appears.

Expand Installed > Visual C# Items, and then choose the Application Configuration File template.

In the Name text box, enter a name, and then choose the Add button. A file named app.config is added to your project.

Related