Search code examples
c#app-configconfigurationmanager

Problems with user defined app.config data


I have some problems to create a fully implemented ConfigurationCollection with the following user defined section in the app.config.file

<OPCSection>
    <OPCDefinitions tab_id="9">
      <OPC column_id="G" datatypename="State" nameontab="State" />
      <OPC column_id="H" datatypename="Fault1" nameontab="Front end positon not reached" />
      <OPC column_id="I" datatypename="Fault2" nameontab="Rear end positon not reached" />
    </OPCDefinitions>
    <OPCDefinitions tab_id="10">
      <OPC column_id="G" datatypename="State" nameontab="State" />
      <OPC column_id="H" datatypename="Fault1" nameontab="Front end positon not reached" />
      <OPC column_id="I" datatypename="Fault2" nameontab="Rear end positon not reached" />
    </OPCDefinitions>
  </OPCSection>

I had this section before but I got an error (item is already added)...

  <OPCSection>
    <OPCDefinitions>
      <add tab_id="9" column_id="G" datatypename="State" nameontab="State" />
      <add tab_id="9" column_id="H" datatypename="Fault1" nameontab="Front end positon not reached" />
      <add tab_id="10" column_id="H" datatypename="Fault1" nameontab="Front end positon not reached" />
      <add tab_id="10" column_id="I" datatypename="Fault2" nameontab="Rear end positon not reached" />
    </OPCDefinitions>
  </OPCSection>

What I need now is a class where I can access these fields from. I also want to access those fields by name like e.g.

classname.ColumnID

I hope someone can help me out to get this...

Thanks in advance.


Solution

  • Look up the documentation for ConfigurationManager

    It supports user defined appSettings like here:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
        </startup>
      <appSettings>
        <add key="Setting1" value="May 5, 2014"/>
        <add key="Setting2" value="May 6, 2014"/>
      </appSettings>
    </configuration>