Application Configuration Files in VC# (App.config > <app>.exe.config)
I am creating a application configuration file. I am interested in using custom sections, not just the default <appSettings> section. I have created handlers to read the custom section shown below. I want to update or write back to sections in the configuration file. How can I do this?
<?xml version="1.0" encoding="utf-8" ?> All of the values above for TimeSpan, DateTimeOfLastBackup and all the values described in the <appSettings></appSettings> will require updating. I can successfully read the values in the sections above, but I do not know the direction to go on updating these values from the application. Shown below, I additionally want to read these sections which have yet to be defined in the <configSections></configSections> section. I have a <TrendColors></TrendColors> section that has node-list of color elements with attributes. I also have a <Views></Views> section that has subsections, node list <ChildForm></ChildForm>, each ChildForm section having one attribute. And, each ChildForm section has Trend elements with multiple attibutes. How should I read these? None of the section-elements nor property-attributes below require updating from the application at this time.
<configuration>
<configSections>
<sectionGroup name="TimeSpan">
<section
name="FromDateTime"
type="ConfigurationSectionObjects.DateTimeConfigHandler,AcuityTrendCharter"/>
<section
name="ToDateTime"
type="ConfigurationSectionObjects.DateTimeConfigHandler,AcuityTrendCharter"/>
</sectionGroup>
<section
name="DateTimeOfLastBackup"
type="ConfigurationSectionObjects.DateTimeConfigHandler,AcuityTrendCharter"/>
</configSections>
<TimeSpan>
<FromDateTime>
<Year>2005</Year>
<Month>8</Month>
<Day>1</Day>
<Hour>12</Hour>
<Minute>30</Minute>
</FromDateTime>
<ToDateTime>
<Year>2005</Year>
<Month>8</Month>
<Day>3</Day>
<Hour>12</Hour>
<Minute>30</Minute>
</ToDateTime>
</TimeSpan>
<DateTimeOfLastBackup>
<Year>2005</Year>
<Month>8</Month>
<Day>1</Day>
<Hour>12</Hour>
<Minute>30</Minute>
</DateTimeOfLastBackup>
<appSettings>
<add key="BackupDirectory" value=""/>
<add key="DatabaseDirectory" value="c:\\"/>
<add key="DatabaseFileName" value="transaction.mdb"/>
</appSettings>
</configuration>
</configuration>
<!-- List of Trend Colors used to plot points and trend lines. -->
<!-- Colors for additional trends should be added as needed. -->
<TrendColors>
<Color
Name="Red"
ID="0xFF0000"/>
<Color
Name="Green"
ID="0x00FF00"/>
<Color
Name="Blue"
ID="0x0000FF"/>
<Color
Name="Red/Blue"
ID="0xFF00FF"/>
<Color
Name="Red/Green"
ID="0xFFFF00"/>
<Color
Name="Green/Blue"
ID="0x00FFFF"/>
<Color
Name="Grey"
ID="0x808080"/>
</TrendColors>
<!-- List of Views each with corresponding trends. -->
<Views>
<ChildForm Name="View1">
<Trend
Name="Trend1"
ID="0001"/>
<Trend
Name="Trend2"
ID="0002"/>
<Trend
Name="Trend3"
ID="0003"/>
</ChildForm>
<ChildForm Name="View2">
<Trend
Name="Trend4"
ID="0004"/>
<Trend
Name="Trend5"
ID="0005"/>
<Trend
Name="Trend6"
ID="0006"/>
</ChildForm>
<ChildForm Name="View3">
<Trend
Name="Trend7"
ID="0007"/>
<Trend
Name="Trend8"
ID="0008"/>
<Trend
Name="Trend9"
ID="0009"/>
</ChildForm>
<ChildForm Name="View4">
<Trend
Name="Trend10"
ID="0010"/>
<Trend
Name="Trend11"
ID="0011"/>
<Trend
Name="Trend12"
ID="0012"/>
</ChildForm>
<ChildForm Name="View5">
<Trend
Name="Trend13"
ID="0013"/>
<Trend
Name="Trend14"
ID="0014"/>
<Trend
Name="Trend15"
ID="0015"/>
</ChildForm>
<ChildForm Name="View6">
<Trend
Name="Trend16"
ID="0016"/>
<Trend
Name="Trend17"
ID="0017"/>
<Trend
Name="Trend18"
ID="0018"/>
</ChildForm>
<ChildForm Name="View7">
<Trend
Name="Trend19"
ID="0019"/>
<Trend
Name="Trend20"
ID="0020"/>
<Trend
Name="Trend21"
ID="0021"/>
</ChildForm>
<ChildForm Name="View8">
<Trend
Name="Trend22"
ID="0022"/>
<Trend
Name="Trend23"
ID="0023"/>
<Trend
Name="Trend24"
ID="0024"/>
</ChildForm>
<ChildForm Name="View9">
<Trend
Name="Trend25"
ID="0025"/>
<Trend
Name="Trend26"
ID="0026"/>
<Trend
Name="Trend27"
ID="0027"/>
</ChildForm>
<ChildForm Name="View10">
<Trend
Name="Trend28"
ID="0028"/>
<Trend
Name="Trend29"
ID="0029"/>
<Trend
Name="Trend30"
ID="0030"/>
</ChildForm>
</Views>
</configuration>
Any advise would be helpful.
James

