471,071 Members | 7,703 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

reading .config file

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.Str ing)).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.
Nov 16 '05 #1
2 1968
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"?>

--
Scott
http://www.OdeToCode.com/


On Wed, 6 Oct 2004 11:31:37 -0400, "jassi" <je**********@hotmail.com>
wrote:
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.St ring)).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.


Nov 16 '05 #2
><?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();


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
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sami | last post: by
1 post views Thread by Paul Fi | last post: by
8 posts views Thread by Martin Eyles | last post: by
1 post views Thread by comic_rage | last post: by
3 posts views Thread by Eroc | last post: by
5 posts views Thread by alf | last post: by
1 post views Thread by M Irfan | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.