473,395 Members | 1,978 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 2059
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.