473,378 Members | 1,372 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,378 software developers and data experts.

ConfigurationManager in .net 2.0

Hi,

I am tring to read the custom configuration form a config file but I
am not getting any way to read the data from the config file. Here is
tha sample.

config file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Group1">
<section name="Section1"
type="System.Configuration.DictionarySectionHandle r, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'"/>
</sectionGroup>
</configSections>

<Group1>
<Section1>
<add key="server" value="aServer"></add>
<add key="type" value="private"></add>
<add key="name" value="aName"></add>
</queueConfiguration>
</Group1>
</configuration>

code
private static Hashtable readQueueConfiguration()
{
string searchString = "/";
char[] searchChar = searchString.ToCharArray();
string location =
Assembly.GetExecutingAssembly().CodeBase.Substring (8,
Assembly.GetExecutingAssembly().CodeBase.LastIndex OfAny(searchChar) -
8).Replace("/", "\\");

ExeConfigurationFileMap configFileMap = new
ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = location + "\
\MyFile.config";
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(co nfigFileMap,
ConfigurationUserLevel.None);

ConfigurationSection section = config.GetSection("Group1/
Section1");
return section as HashTable;
At this point I am getting a complier error saying cannot convert
ConfigurationSection to HashTable using new opeation. I tried using
cast as well i.e (HashTable)section but got same error message.

I really don't understand how to read the setting i.e. server, type
and name using this new ConfigurationManager.

Do I really need to implement my own custome section handler?

Belive me I tried googling and got many example on how to read
appSetting, connectionString or even writing own custom handler but
couldn't find any answer on how to use predefined handler such as
DictionarySectionHandler.

Any help or point to some artical will be veryhelpful.

Jul 4 '07 #1
1 1665
Sorry but the configuration file is as given below
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="Group1">
<section name="Section1"
type="System.Configuration.DictionarySectionHandle r, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>

</sectionGroup>
</configSections>

<Group1>
<Section1>
<add key="server" value="vm-wxp-pb006"></add>
<add key="type" value="private"></add>
<add key="name" value="RequestQueue"></add>
</Section1>
</Group1>
</configuration>

Note there is difference in the public key for dictionary handler...

Just for my info, how to get the public key for each type or assembly?

Jul 4 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Debus | last post by:
Hi, I try to read a value from app.config file using this code: string s=System.Configuration.ConfigurationManager.AppSettings.ToString(); I got the compiler error: Error 1 The type or...
2
by: Myo Zaw | last post by:
hi, can i use configurationmanager in .net 2.0 windows form. cause i have an app.config file and i couldn't extract the data from there by using configurationmanager nor 1.1 feature. do u have any...
2
by: robertino | last post by:
Hi All, (VS 2005 Pro, Win XP Pro) I'm trying to read some app settings from my app.config file (normal Win app), have included the System.Configuration namespace in my app, but when I try to...
3
by: natasha | last post by:
Hello everybody, you can use ConfigurationManager.AppSettings.Set method (ConfigurationManager is in System.Web.Configuration namespace) to store a modified value from web.config. To be...
1
by: shapper | last post by:
Hello, I create a few VB classes under app_code of a web site. Now I am trying to create a library project. Something strange is going on. I have the following line: Dim connectionString As...
3
by: Mark | last post by:
I am trying to read the appsettings section of a configuration file using the ConfigurationManager object (ASP.NET application) with the following three lines but for some reason the...
4
by: Jim in Arizona | last post by:
I've been using VB 2005 for a few years now. My entire coding history is VB related. This weekend I decided to start learning C#. I'm at work now and decided to do some coding in C# that I would...
2
by: remya1000 | last post by:
i'm using VB.NET 2003. Last time while i did a program in Vb.Net 2005, i use "Configuration". and i could read and write to that XML configuration file like the example below. CODES:...
2
by: pantagruel | last post by:
Hi, I have a Visual studio 2005 project that runs as a Windows Service. In it I have declared that I am using System.Configuration. I have set one application setting for the service using the...
3
by: Jeff | last post by:
I have a solution with two projects. Project A is the startup project, while Project B serves as the project with the data logic. At run time, the first thing I need to do is write to Project...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.