sari
sari

Reputation: 183

how to use with app.config

this is my app config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="version" value="1.0.0."/> 
  </appSettings>
</configuration>

this is my code

txtVersion.Text = ConfigurationSettings.AppSettings["version"];

I get null value

Upvotes: 0

Views: 175

Answers (3)

badbod99
badbod99

Reputation: 7526

There is nothing wrong with your code, although ConfigurationManager now replaces ConfigurationSettings.

If you are running in Visual Studio, make sure your app.config has been copied to the bin\debug (or bin\release depending on if you are in release or debug mode) and has been correctly renamed to [yourappname].exe.config.

Make sure you have added the app.config to your project within Visual Studio (rather than just creating the file in the dir). Alternatively, put the file manually in the bin\debug dir with the correct name as above and try again.

Upvotes: 1

user333306
user333306

Reputation:

You can use C# Settings instead.

http://msdn.microsoft.com/en-us/library/aa730869(VS.80).aspx

Upvotes: 1

Darin Dimitrov
Darin Dimitrov

Reputation: 1039538

Try using the ConfigurationManager class:

txtVersion.Text = ConfigurationManager.AppSettings["version"];

Upvotes: 2

Related Questions