473,395 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2058
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sami | last post by:
Hello, I have this problem that I need your help with : I am reading a config file that contain the following : 2004 update
1
by: Paul Fi | last post by:
I have this problem with .NET remoting: my remote class is called RemoteHandler which implements an interface called IEazyRemoting which has only one method to be implemented which is my server...
3
by: spacekid | last post by:
Hi there I am exposing a c# assembly as a COM component (regasm /codebase) and calling it from classic asp. When I try to call the ConfigurationSettings.AppSettings function in the c# assembly,...
8
by: Martin Eyles | last post by:
Hi, I have a configuration file I made in xml which I am using to name a database server. (this way I can deploy my web page on various servers, and just change this file to make it work)....
1
by: comic_rage | last post by:
Hi, I am trying to read from my application config file and keep getting null. Here is my config file My application is called SampleApp.exe
3
by: Eroc | last post by:
I'm new to XML files so I'm kinda lost here. I found some example code on reading an XML file. My objective is simple. Read the whole XML file into memory. Here is part of my code: Private...
10
by: Ryan | last post by:
I've created a custom configuration section that inherits (naturally) from System.Configuration.ConfigurationSection. The configuration section is working 99% fine, however I keep coming across a...
5
by: alf | last post by:
Hi folks, I'm trying to read a web.config section using RoleManagerSection settings = (RoleManagerSection)System.Configuration.ConfigurationManager.GetSection("system.web/roleManager"); and I...
1
by: M Irfan | last post by:
Hello all, Recently I have started working in .NET 2.0. I am developing a web service application that references a DLL component written in C# 2.0. The component has its own config file which...
1
by: vijayarl | last post by:
Hi Everyone, i have the written this logic : basically a file operation open (CONFIGFILE, "$config_file") or die; while (<CONFIGFILE>) { chomp;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.