Hi Everyone,
I realize that writing to the app.config file may not be best practices. However, how do you write to a user defined sectionGroup in the app.config file. I can't figure it out thanks.
-zd
Printable View
Hi Everyone,
I realize that writing to the app.config file may not be best practices. However, how do you write to a user defined sectionGroup in the app.config file. I can't figure it out thanks.
-zd
I sometimes updtae a App.config file by writing over the entire file since it's xml. I never got any problems with this so i continue to overwrite the app.config if there is any need for configuration changes to a program.
This user defined group you asked about, you want to give an example of such a group with xml?
Jennifer.
I guess technically it is considered a sectionGroup.
In this part of my app.config I declare my sectionGroup
Here is where I set the valuesCode:<configSections>
<sectionGroup name="SerialPort">
<section name="SerialPortInformation" type="Scale_Simulator.SerialPortConfigHandler,Scale Simulator"/>
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Scale_Simulator.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
When you first start the program a serial port won't be setup that is why they are empty.Code:<SerialPort>
<SerialPortInformation>
<port></port>
<baudrate></baudrate>
<databits></databits>
<parity></parity>
<stopbits></stopbits>
<flow></flow>
</SerialPortInformation>
</SerialPort>
What I have so far for saving is this
The information is not saving to the file.Code:Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.GetSection("SerialPort/SerialPortInformation").SectionInformation.SetRawXml("<SerialPortInformation>" + "\r\n" + "<port>" + cboPort.Text + "</port>" + "\r\n" + "<baudrate>" + cbobaudRate.Text + "</baudrate>" + "\r\n" + "<databits>" + cboDataBits.Text + "</databits>" + "\r\n" + "<parity>" + cboParity.Text + "</parity>" + "\r\n" + "<stopbits>" + cboStopBits.Text + "</stopbits>" + "\r\n" + "<flow>" + cboHandShake.Text + "</flow>" + "\r\n" + "</SerialPortInformation>");
config.Save(ConfigurationSaveMode.Full, true);
ConfigurationSection mysection = config.GetSection("SerialPort/SerialPortInformation");
Is there a better way to do this????
thanks,
-zd