0

I created a new config file called "samplesApp.config" and it looks as below.

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

and I am trying to read value from above config file as shown. but it is not reading value from new config file.how can I read values from new config file using c#

string port = ConfigurationManager.AppSettings["IDNUMBER"];
N.RaviKumar
  • 275
  • 1
  • 5
  • 14
  • Possible duplicate of [Loading custom configuration files](http://stackoverflow.com/questions/505566/loading-custom-configuration-files) – Adnan Umer Nov 10 '16 at 05:59
  • 3
    call you file `app.config`or `web.config`. Or is your intention to call it `samplesApp.config`? – Daniel Nov 10 '16 at 06:01

1 Answers1

0

I tried your code and it works

I think your problem is due to your config file name, you must have the following name: 'samplesApp.exe.config' and not 'samplesApp.config'

The best practice is to create within your root project, a text file with the name: App.Config, so when you run the program will be created in the bin folder, the correct configuration file.

If you are developing a web application, you must create a file with the following name: 'Web.Config'

Giovanni Russo
  • 273
  • 2
  • 7