| | |
Windows Form, custom configuration section
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
As usual, the examples I find for this either don't work, or don't apply.
I want to store, essentially, a text file, within my app.config file, and access it programmatically.
Here's a simplified version:
Two questions:
1. What goes in the "type" attribute, which I've colored red?
2. How would I retrieve the "prolog" element from the "PostScript" section of this file?
Note: this is read-only, I do not need to change/set the values in the customSection as so many examples assume.
I want to store, essentially, a text file, within my app.config file, and access it programmatically.
Here's a simplified version:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="PostScript" type="" />
</configSections>
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
</appSettings>
<PostScript>
<prolog>
<![CDATA[
My big long
text file
goes here.
]]>
</prolog>
</PostScript>
</configuration>1. What goes in the "type" attribute, which I've colored red?
2. How would I retrieve the "prolog" element from the "PostScript" section of this file?
Note: this is read-only, I do not need to change/set the values in the customSection as so many examples assume.
OK... Maybe I can weigh in on this one.
Using what VERY LITTLE I currently know about XML (learning more every day), it appears that the type attribute specifies a type that's outlined in a particular XML schema. So, you could have an XML schema that defines a type, and then you'd use the type="xs:foo_my_schema" to tell the parser that's what your type is.
What does that mean? I dunno. I'll reiterate that I don't know a whole lot about XML, and I know especially less about XML Schemas. (haven't found a good book on it yet, really) But, maybe this link will help:
http://www.w3.org/TR/xmlschema-1/
I at least was able to use it to discern what the type= bit is used for. I'm guessing that if you don't use a schema, it's optional.
Using what VERY LITTLE I currently know about XML (learning more every day), it appears that the type attribute specifies a type that's outlined in a particular XML schema. So, you could have an XML schema that defines a type, and then you'd use the type="xs:foo_my_schema" to tell the parser that's what your type is.
What does that mean? I dunno. I'll reiterate that I don't know a whole lot about XML, and I know especially less about XML Schemas. (haven't found a good book on it yet, really) But, maybe this link will help:
http://www.w3.org/TR/xmlschema-1/
I at least was able to use it to discern what the type= bit is used for. I'm guessing that if you don't use a schema, it's optional.
Alex Cavnar, aka alc6379
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
Here's what I've learned.
1) You have to add the System.Configuration class as a reference, not just a "using" namespace declaration.
2) The "type" does indeed need to match a schema, in this case Microsoft's, and they have only 3 values, all related to a NameValue organization. Mine isn't, mine is Element-Node-Element.
3) You can add a custom type, but then you have to create a class to provide the handler for the type
4) All of this is ridiculous, because you can simply use an XmlTextReader to do a forward-only, read-only pass through any XML file, including the config.
So, I'll re-visit and really figure this all out when I need an application that can get/set its own complex configuration settings. For now, I just stored everything under the appsettings section as key-value pairs, which you can access directly.
I personally think .NET 2.0 over-complicated the Configuration aspect.
1) You have to add the System.Configuration class as a reference, not just a "using" namespace declaration.
2) The "type" does indeed need to match a schema, in this case Microsoft's, and they have only 3 values, all related to a NameValue organization. Mine isn't, mine is Element-Node-Element.
3) You can add a custom type, but then you have to create a class to provide the handler for the type
4) All of this is ridiculous, because you can simply use an XmlTextReader to do a forward-only, read-only pass through any XML file, including the config.
So, I'll re-visit and really figure this all out when I need an application that can get/set its own complex configuration settings. For now, I just stored everything under the appsettings section as key-value pairs, which you can access directly.
I personally think .NET 2.0 over-complicated the Configuration aspect.
Last edited by tgreer; May 19th, 2006 at 1:51 pm.
I'm really dreading having to fool with configuration for some reason. I can understand C# well enough, but I'm having a tough time with XML. I'm just hoping that when the need finally does arise for me to really use an app.config file, I'll have a little more knowledge under my belt regarding the topic.
Alex Cavnar, aka alc6379
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
It isn't too bad, as long as you don't break their strict rules. If you do break the rules, like I was wanting to do, they provide all sorts of "helpful" classes etc., which are anything but.
I'm putting more and more into .config as time goes by. I find myself thinking, "if I hard-code this, they'll sure enough want to change it, so I'll put it in the config file instead".
Not logic, of course, but folder settings, label text, filenames, all the database connection strings, etc.
I'm putting more and more into .config as time goes by. I find myself thinking, "if I hard-code this, they'll sure enough want to change it, so I'll put it in the config file instead".
Not logic, of course, but folder settings, label text, filenames, all the database connection strings, etc.
![]() |
Similar Threads
- Unrecognized configuration section 'forms' (ASP.NET)
- Need Help in Windows form inC# (C#)
- Using Windows XP Visual Styles with Controls on Windows Forms (VB.NET)
- "Not Responding" Message in Windows Form Application (ASP.NET)
Other Threads in the C# Forum
- Previous Thread: C# Project
- Next Thread: Sound output meter
Views: 9532 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






