none
Reading from App.Config c# 2.0 console application

    Question

  • 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

    Friday, June 02, 2006 1:35 PM

Answers

  • 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
    Friday, June 02, 2006 1:58 PM
    Moderator
  • 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.
    • Marked as answer by Gmoney1404 Thursday, November 19, 2009 10:14 AM
    Friday, June 02, 2006 11:27 PM
    Moderator

All replies

  • 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
    Friday, June 02, 2006 1:58 PM
    Moderator
  • Than you for your help but I have already added the ref for the System.Configuration namespace as per my code sample.
    Friday, June 02, 2006 2:37 PM
  • 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


    Friday, June 02, 2006 3:34 PM
  • 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.
    • Marked as answer by Gmoney1404 Thursday, November 19, 2009 10:14 AM
    Friday, June 02, 2006 11:27 PM
    Moderator
  • Yes that works my bad for not getting your point

     

    Cheers

     

    Monday, June 05, 2006 9:37 AM
  • You can use this

    ConfigurationSettings.AppSettings.GetValues. It has 2 overloads one is index (int) another name (string)
    Tuesday, July 29, 2008 12:54 PM
  • 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

    It Worked for me too. Nice Answer Thanks

    • Proposed as answer by Danish Farman Saturday, December 08, 2012 12:40 PM
    Saturday, December 08, 2012 12:40 PM