473,792 Members | 3,005 Online
Bytes | Software Development & Data Engineering Community
+ 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" ?>
<configuratio n>
<configSections >
<section name="Regions" type="ConfigSec tionHandler.MyS ectionHandler,
ConfigSectionHa ndler"/>
</configSections>
<Regions>
<Australia value="0"/>
</Regions>
</configuration>

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

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

calling method:
rivate void Form1_Load(obje ct sender, System.EventArg s e)
{
Hashtable hash;
ConfigSectionHa ndler.MySection Handler config = new
ConfigSectionHa ndler.MySection Handler();
hash =
(Hashtable)conf ig.Create(null, null,(System.Xm l.XmlNode)Syste m.Configuration .ConfigurationS ettings.GetConf ig("Regions")) ;
for(int i=0;i<hash.Coun t;i++)
{
MessageBox.Show (hash.Keys.ToSt ring());
}
}

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

Regards,
NJ

May 13 '06 #1
1 7785

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*****@hotmai l.com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.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" ?>
<configuratio n>
<configSections >
<section name="Regions" type="ConfigSec tionHandler.MyS ectionHandler,
ConfigSectionHa ndler"/>
</configSections>
<Regions>
<Australia value="0"/>
</Regions>
</configuration>

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

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

calling method:
rivate void Form1_Load(obje ct sender, System.EventArg s e)
{
Hashtable hash;
ConfigSectionHa ndler.MySection Handler config = new
ConfigSectionHa ndler.MySection Handler();
hash =
(Hashtable)conf ig.Create(null, null,(System.Xm l.XmlNode)Syste m.Configuration .
ConfigurationSe ttings.GetConfi g("Regions")) ; for(int i=0;i<hash.Coun t;i++)
{
MessageBox.Show (hash.Keys.ToSt ring());
}
}

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
1849
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 ... for a while. At random points in time my section handler stops working and throws the exception: Configuration Error Description: An error occurred during the processing of a configuration
4
1922
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"> <site url="/blog/"> <mode value="live">
2
3222
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> <sectionGroup name="cbsoffice"> <section name="data" type="CbsOffice.ProviderConfigurationHandler,CbsOffice"/>
3
2820
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 servicing a number of different web service operations from a single application, and because it's all XML, I've been scoping everything to a specific namespace targeting a specific application (these are all InfoPath forms). It seems that the...
6
3802
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" type="ComIT.Applications.Common.ConfigurationSections.MyHandler" allowLocation="true" allowDefinition="Everywhere" /> </configSections>
6
4817
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 install the dll to the same directory as the exe which uses it, everything works as expected but if I load the dll in any other directory, I get the following error... 2007-02-04 16:36:51,171 DEBUG CentrifugeBHO.CentrifugeBHO - dllPath =...
7
10828
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 code. The configuration section is contained within the exe (it's a simple test case!) and everything works well debugging within the IDE or if the application is deployed on a drive or share that has been granted full trust. For the share the...
2
5116
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 = Windows Forms class B = a singleton hosted within A. B is responsible for dynamically loading classes X, Y, and Z.
0
1623
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 level web.config and an application level web.config, with the application web.config inheriting from the root level web.config. I am receiving the following message when compiling the web application... "....Section or group name...
0
10430
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9033
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5436
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4111
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 we have to send another system
2
3719
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.