• 0

App.Config reading


Question

I am trying to read the app.config of a winform exe from within a DLL that is called by the EXE.

I am using the code given below, the variable 'config' is picking up the EXE ok, but how do I access the app config settings from here? I want to retrieve the value 'MyValue'.

the variable 'configSection' I am using seems to hold nothing of use.

Any ideas?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

xml version="1.0" encoding="utf-8" ?>

<configuration>



	  <appSettings>



			<add key="ApplicationTitle" value="DevAsp Application Configuration Sample" />

			<add key="ApplicationHeaderText" value="DevAsp" />



	  appSettings>



	  <connectionStrings>



			<add name="ConnectionString" connectionString="user id=DevAsp;data source=Northwind;persist security info=True;initial catalog=Comments;password=abc"

			providerName="System.Data.SqlClient" />



	  connectionStrings>



configuration>

U can retrieve this information from form button using

private void Form1_Load(object sender, EventArgs e)

		{

			this.Text = ConfigurationSettings.AppSettings["ApplicationTitle"];



			label3.Text = ConfigurationSettings.AppSettings["ApplicationHeaderText"];

		}





		private void button1_Click(object sender, EventArgs e)

		{

			richTextBox1.Text = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();



			richTextBox1.Text += "\n\n" + ConfigurationManager.ConnectionStrings["ConnectionString"].ProviderName.ToString();

		}

U didnt provide any detail code for your problem....

So hope this code would be of some help :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.