reading .config file


J

jassi

Hi,

i have an app.config file as follows :

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

<appSettings>

<add key="button1.Text" value="cc1"/>

</appSettings>

</configuration>

I am reading the above file in C# as follows :

System.Configuration.AppSettingsReader myreader = new
System.Configuration.AppSettingsReader();

int i;

Button btn;

for(i=0;i<=4;i++)

{

btn = new Button();

btn.Text =
myreader.GetValue("button1.Text",typeof(System.String)).ToString();

}

But when i run the application it throws the exception- >
'System.Configuration.ConfigurationException'. In the description it says
that ->. Expected 'NAME'. Line 1, position 37. What is wrong with my .config
xml file ??

thanks in advance.
 
Ad

Advertisements

S

Scott Allen

Hi Jassi:

It looks as if the opening processing instrcution is just missing a
'?' at the end, i.e.:

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

Advertisements

M

Marc Scheuner [MVP ADSI]

<configuration>
<appSettings>
<add key="button1.Text" value="cc1"/>
</appSettings>
</configuration>

I am reading the above file in C# as follows :

System.Configuration.AppSettingsReader myreader = new
System.Configuration.AppSettingsReader();

Why so complicated??? Just use:

strTemp = ConfigurationSettings.AppSettings["button1.Text"];

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top