how to get value from app.config file

iam not able to get value from app.config. what iam wrong....?

Page 1 of 1

2 Replies - 44503 Views - Last Post: 12 March 2009 - 04:56 AM Rate Topic: -----

#1 nagisetty1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-March 09

how to get value from app.config file

Posted 12 March 2009 - 12:46 AM

file: app.config

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

</configuration>



Class1 :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace sampleappDLL
{
    public class Class1
    {
        string name = Convert.ToString(ConfigurationSettings.AppSettings["Name"]);
        public string get()
        {
            return name;
        }
    }
}



this is another solution named as sampleapp

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;
using sampleappDLL;



namespace sampleapp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
           
            string nam;
            sampleappDLL.Class1 obj = new sampleappDLL.Class1();
            nam=obj.get();
            textBox1.Text = nam;
        }
    }
}



what iam wrong..........? please give me guide lines..................

*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 12 March 2009 - 04:54 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how to get value from app.config file

#2 b.ihde   User is offline

  • D.I.C for life
  • member icon

Reputation: 45
  • View blog
  • Posts: 1,070
  • Joined: 29-September 08

Re: how to get value from app.config file

Posted 12 March 2009 - 01:04 AM

Hello and welcome to DreamInCode!

Please use our code-tags: [ c o d e ] code here [ / c o d e ] (without spaces..)

regards

Ben
Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6258
  • View blog
  • Posts: 24,026
  • Joined: 23-August 08

Re: how to get value from app.config file

Posted 12 March 2009 - 04:56 AM

You haven't told us what's wrong. Is it crashing?

I would not use get() as the method name, as it's likely a reserved word.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1