473,473 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

custom configuration section in app.config

Hi I am trying to experiment with a custom configuration section in
app.config but it just doesnt work.

app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Regions" type="ConfigSectionHandler.MySectionHandler,
ConfigSectionHandler"/>
</configSections>
<Regions>
<Australia value="0"/>
</Regions>
</configuration>

MySectionHandler.cs:
public object Create(object parent, object configContext, XmlNode
section)
{
object obj=null;
// TODO: Add MySectionHandler.Create implementation
try
{
hash = new Hashtable();
if(section.Name == "Regions")
{
foreach(XmlNode child in section)
{

hash.Add(child.Name.ToString(),child.Value.ToStrin g());
}
obj=hash;
}
}
catch
{
obj=null;
}
finally
{
}
return obj;
}

calling method:
rivate void Form1_Load(object sender, System.EventArgs e)
{
Hashtable hash;
ConfigSectionHandler.MySectionHandler config = new
ConfigSectionHandler.MySectionHandler();
hash =
(Hashtable)config.Create(null,null,(System.Xml.Xml Node)System.Configuration.ConfigurationSettings.Ge tConfig("Regions"));
for(int i=0;i<hash.Count;i++)
{
MessageBox.Show(hash.Keys.ToString());
}
}

If anyone can help please let me know. The GetConfig returns nothing

Regards,
NJ

May 13 '06 #1
1 7772

I have several config section handlers at:
http://spaces.msn.com/sholliday/ 12/1/2005 2/8/2006 entries.

They aren't config section examples for academic purposes, I created them
for real use.

But should give you a good example.

<np*****@hotmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
Hi I am trying to experiment with a custom configuration section in
app.config but it just doesnt work.

app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="Regions" type="ConfigSectionHandler.MySectionHandler,
ConfigSectionHandler"/>
</configSections>
<Regions>
<Australia value="0"/>
</Regions>
</configuration>

MySectionHandler.cs:
public object Create(object parent, object configContext, XmlNode
section)
{
object obj=null;
// TODO: Add MySectionHandler.Create implementation
try
{
hash = new Hashtable();
if(section.Name == "Regions")
{
foreach(XmlNode child in section)
{

hash.Add(child.Name.ToString(),child.Value.ToStrin g());
}
obj=hash;
}
}
catch
{
obj=null;
}
finally
{
}
return obj;
}

calling method:
rivate void Form1_Load(object sender, System.EventArgs e)
{
Hashtable hash;
ConfigSectionHandler.MySectionHandler config = new
ConfigSectionHandler.MySectionHandler();
hash =
(Hashtable)config.Create(null,null,(System.Xml.Xml Node)System.Configuration.
ConfigurationSettings.GetConfig("Regions")); for(int i=0;i<hash.Count;i++)
{
MessageBox.Show(hash.Keys.ToString());
}
}

If anyone can help please let me know. The GetConfig returns nothing

Regards,
NJ

May 13 '06 #2

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

Similar topics

0
by: Søren Lund | last post by:
Hello, I have implemented a custom config section handler by implementing the IConfigurationSectionHandler interface. I have registered this handler in web.config and everything works fine ......
4
by: Nick Gilbert | last post by:
Hi, I would like the ability to store the configuration settings for all versions of my site in a single web.config file by using different sections. Eg: <siteConfig> <machine name="XENON">...
2
by: murl | last post by:
Below is what i have as the custom section in the web.config file... <?xml version="1.0" encoding="utf-8" ?> <configuration> <!-- register local configuration handlers --> <configSections>...
3
by: rdcpro | last post by:
Hi all, I've been building a nifty deserializing configuration handler that I use in conjunction with my web.config in an ASP.NET web app. This is working quite well, but I'm planning on...
6
by: Tabi | last post by:
Hi, I want to create a custom section in my web.config that can hold my custom values. I created a section in web.config as written below. <configSections> <section name="myCustomSection"...
6
by: Jeff Hegedus | last post by:
I have a dll that requires some configuration data. I put the configuration data in a custom configuration section in a config file that is loaded in the installation folder of the dll. If I...
7
by: =?Utf-8?B?RG91Z2llIEJyb3du?= | last post by:
Hi I've written custom configuration section (inherits from System.Configuration.ConfigurationSection) to simplify the contents of the config file and to make life easier when accessing them in...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
0
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I have a web.config custom configuration section using asp.net 2.0 configuration APIs. My custom configuration section inherits from System.Configuration.ConfigurationSection. I have a IIS root...
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...
1
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.