Karim
Karim

Reputation: 6283

what is the name of the app.config of a winforms app? and how can i know that the app loaded that app.config?

well i basically cant add an app.config file to my win forms project.
and i dont know if the application actually uses it or no.
i used "Add" > "New Item" > "Application Configuration File" but well i dont know if the app reads the data from the file or no.
so how can i know that the app actually reads that file?
thanks

Upvotes: 1

Views: 3085

Answers (3)

Fredrik Mörk
Fredrik Mörk

Reputation: 158309

The file will be called "yourappname.exe.config" in the output directory of your project. In order to test whether your application uses the file or not you can add a simple test to the code:

In the app.config file:

<configuration>
   <appSettings>
       <add key="testValue" value="Testing testing, one two three" />
   </appSettings>
</configuration>

Basically anywhere in your application's code (preferably code that is executed during startup):

MessageBox.Show(ConfigurationManager.AppSettings["testValue"]);

You should see a message box with the value from the config file.

Upvotes: 4

Chris
Chris

Reputation: 1001

When you build, the app.config file will be copied as NameOfApplication.exe.config to the debug or release folder alongside the exe. That is the file that will be read.

Upvotes: 0

AllenG
AllenG

Reputation: 8190

1) The app.config file compiles as [yourProjectName].exe.config.
2) If any (basic) calls to ConfigurationManager work, it has read your app.config.

Upvotes: 1

Related Questions