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