Reading from App.Config c# 2.0 console application

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

The above link tells me to use the ConfigurationManager class to read appsetting elements from the app.config.

When I do this VS2005 C# 2.0 console application the ConfigurationManager class is not reconised. Can someone please point out this simple command.

Syntax used:

using

System;

using

System.Collections.Specialized;

using

System.Collections.ObjectModel;

using

System.Collections;

using

System.Text;

using

System.Configuration;

using

System.Data;

using

System.IO;

string configValueString = System.Configuration. NO ConfigurationManager

someone please tell me how to read xml from app.config from a console app in c# 2.0



Answer this question

Reading from App.Config c# 2.0 console application

  • Arun Murali

    Here is how to do slightly more advanced stuff like reading just any config file and making updates... how to use System.Configuration to do configuration management

    http://blogs.covarius.com/PermaLink,guid,4b1fe1b7-883e-444b-92f9-f8c4758d6c79.aspx


  • Prabu.

    What I am telling you is different to your code....

    Putting in the "using System.Configuration" statement is not enough. You need to do what I detailed in my previous post (i.e. go to Project > Add Reference....).

    If you have already done that and it's not working for you, then sorry 'bout that.


  • CPark72

    Than you for your help but I have already added the ref for the System.Configuration namespace as per my code sample.
  • Hans van Vliet

    Yes that works my bad for not getting your point

    Cheers


  • FcoLomas

    Hi there,

    It is true that you can't get the ConfigurationManager class straight away. You need to add a reference to your project. Try the following steps:

    1) In your IDE, go to the "Project" menu and select "Add Reference" from that menu

    2) A dialog will appear. Select the ".NET" tab from that dialog

    3) Scroll down the list of components and there should be one called "System.Configuration"

    4) Click on the entry in the list called "System.Configuration" and then click "OK" to add it as a reference.

    You should then be able to go System.Configuration.ConfigurationManager (or just ConfigurationManager if you have the appropriate "using" statement in your code).

    Hope that helps a bit, but sorry if it doesn't


  • Hoodwinked

    1) Add reference to System.Configuration
    2) in the code ... Use ConfigurationManager.

    ConfigurationManager.AppSettings[index];


    EDIT :

    ConfigurationManager.AppSettings[yourKeyString];

    if you xml is

    <configuration>
        <configSections>
        </configSections>
       
        <appSettings>

            <add key="Test" value="hello"/>
        </appSettings>
    </configuration>

    Then its going to be

    ConfigurationManager.AppSettings["Test"];

    Good luck



  • Reading from App.Config c# 2.0 console application