ConfigurationManager in .net 2.0

P

-pb-

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.DictionarySectionHandler, 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.LastIndexOfAny(searchChar) -
8).Replace("/", "\\");

ExeConfigurationFileMap configFileMap = new
ExeConfigurationFileMap();
configFileMap.ExeConfigFilename = location + "\
\MyFile.config";
Configuration config =
ConfigurationManager.OpenMappedExeConfiguration(configFileMap,
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.
 
P

-pb-

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.DictionarySectionHandler, 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?
 

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