custom configuration section in app.config

  • Thread starter Thread starter sloan
  • Start date Start date
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.ToString());
}
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.XmlNode)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
 

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

Back
Top