Thread: c# config

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    3

    Question c# config

    Hi I'm trying to implement a simple c# config file within my program. However I cannot figure out why I have an error with "ConfigurationSettings.AppSettings." I thought that this was referenced with "System.Configuration." I was looking for another reference like "System.configuration.ConfigurationSettings" but there isn't one. I'm not sure what I'm doing wrong. I found some simple code off of the internet but I cannot get it to work. Am I placing the code in the wrong part of the form?

    I will list it below. Any help is appreciated! Thanks.


    App.config:

    Code:
    <?xml version="1.0" encoding=    "utf-8" ?>
    
    <configuration>
    
      <appSettings>
    
        <add key="DatabasePath" value="c:\\projects\data\spider.mdb" />
    
        <add key="SupportEmail" value="[email protected]" />
    
      </appSettings>
    
    </configuration>



    Form:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Configuration;
    
    
    namespace ConfigTest2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string dbPath = ConfigurationSettings.AppSettings["DatabasePath"];
                string email = ConfigurationSettings.AppSettings["SupportEmail"];
            }
        }
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    So what happens? Do you get errors?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    3
    Oh sorry i forgot to mention what exactly the error is..

    Code:
    string dbPath = ConfigurationSettings.AppSettings["DatabasePath"];
    string email = ConfigurationSettings.AppSettings["SupportEmail"];
    Both "ConfigurationSettings.AppSettings" are underlined. The errors say:

    Warning 1 'System.Configuration.ConfigurationSettings.AppSet tings' is obsolete: '"This method is obsolete, it has been replaced by System.Configuration!System.Configuration.Configur ationManager.AppSettings"'


    Warning 2 'System.Configuration.ConfigurationSettings.AppSet tings' is obsolete: '"This method is obsolete, it has been replaced by System.Configuration!System.Configuration.Configur ationManager.AppSettings"'

  4. #4
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    These are warnings, your project should still build unless you have turned on "treat warnings as errors". The warning is just telling you what you are currently using is obsolete and you should instead use its suggestion. Also usually I let the IDE create the configuration file for me by going to project settings and clicking on the Settings tab.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where to put a config file
    By KirkHammett in forum C# Programming
    Replies: 2
    Last Post: 01-24-2010, 11:53 PM
  2. using app config to create a dynamic menu
    By dana_cc1 in forum C# Programming
    Replies: 2
    Last Post: 04-29-2008, 11:29 PM
  3. config file interface
    By valis in forum C Programming
    Replies: 3
    Last Post: 08-17-2006, 09:30 PM
  4. Parsing config file in C++
    By Dynamo in forum C++ Programming
    Replies: 12
    Last Post: 09-01-2005, 11:21 AM
  5. knoppix config file
    By sentienttoaster in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-17-2004, 09:23 PM

Tags for this Thread