Custom Configuration file Sections in 2.0

G

Guest

Hi

I'm trying to create a series of config files for my Windows app (some of
which may reside in arbitary locations unrelated to the exe file) and have
been reading various examples using the System.Configuration namespace.

However, I just can't get anything to work using these examples e.g.
http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx - have adapted that
one to work with a win app but get the error :

An error occurred creating the configuration section handler for
myCustomGroup/myCustomSection: Could not load type
'MyConfigSectionHandler.MyHandler' from assembly
'MyCustomConfigurationHandler, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null'.

All I want to do is to be able to read configuration info from an xml config
file such as

<myAppSettings>
<SectionA
Setting1="12"
Setting2="25"
Setting3="another value"
/>
</myAppSettings>

Can somebody point me in the right direction please?

many thanks

Richard Bysouth
 
Y

Yuan Ren[MSFT]

Hi Richard,

Thanks for posting!

For the current issue, the article is related about ASP.NET. If you want to
get the information of element in your customer section, I recommend you
use the ConfigurationManager class in the application. The article form
MSDN gives us more explanation and some sample as below:
http://msdn2.microsoft.com/en-us/library/system.configuration.configurationm
anager(VS.80).aspx

I hope this will be helpful. If you have any issues or concerns, please let
me know. It's my pleasure to be of assistance.

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006. Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 
G

Guest

Yuan

Thanks but I had already read this section of the documentation. What I
don't seem to be able to do with the ConfigurationManager class is to open a
config file in a location other than the same folder as the exe file.
It only has the OpenExeConfiguration and OpenMachineConfiguration methods,
nothing like "OpenConfiguration"?

For example, I would like to be able to do something like:

Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenConfiguration("c:\test\myconfig.config")

Dim sectionA As SectionA = _
config.Sections("SectionA")

messagebox.show (sectionA.Setting1)
---
myconfig.config would look something like this:

<myAppSettings>
<SectionA
Setting1="12"
Setting2="25"
Setting3="another value"
/>
</myAppSettings>

Or am I better off just writing my own code to read the file settings using
XmlReader or similar?

Richard
 
Y

Yuan Ren[MSFT]

Hi Richard,

Thanks for your reply!

As your description, actually the ConfigurationManager class is designed
for the specific config file. If you want to read your own config file, the
XmlReader class is appropriate at the current stage. The following document
from MSDN2 demonstrates how to read the attributes from XML document:
http://msdn2.microsoft.com/en-us/library/e4w1e57w(VS.80).aspx

Hope this will be helpful!

Regards,

Yuan Ren [MSFT]
Microsoft Online Support
======================================================
PLEASE NOTE the newsgroup SECURE CODE and PASSWORD were
updated on February 14, 2006. Please complete a re-registration process
by entering the secure code mmpng06 when prompted. Once you have
entered the secure code mmpng06, you will be able to update your profile
and access the partner newsgroups.
======================================================
When responding to posts, please "Reply to Group" via your newsreader
so that others may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================
 

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

Top