Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / July 2007

Tip: Looking for answers? Try searching our database.

ConfigurationManager in .net 2.0

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
-pb- - 04 Jul 2007 14:17 GMT
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.
-pb- - 04 Jul 2007 14:34 GMT
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?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.