Results 1 to 3 of 3

Thread: Writing to app.config

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Writing to app.config

    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

  2. #2
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Writing to app.config

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Re: Writing to app.config

    I guess technically it is considered a sectionGroup.


    In this part of my app.config I declare my sectionGroup
    Code:
    <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>
    Here is where I set the values
    Code:
    <SerialPort>
        <SerialPortInformation>
          <port></port>
          <baudrate></baudrate>
          <databits></databits>
          <parity></parity>
          <stopbits></stopbits>
          <flow></flow>
        </SerialPortInformation>
      </SerialPort>
    When you first start the program a serial port won't be setup that is why they are empty.

    What I have so far for saving is this

    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");
    The information is not saving to the file.

    Is there a better way to do this????

    thanks,

    -zd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width