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.
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.