Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. ConfigurationManager - how to read/write into a custom section?

ConfigurationManager - how to read/write into a custom section?

Scheduled Pinned Locked Moved C#
questionxmltutorialannouncementworkspace
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zeokat
    wrote on last edited by
    #1

    My config file:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>

    <appSettings>
    <add key="sunshine" value="125" />
    <add key="moonshine" value="50" />
    <add key="seashine" value="10" />
    </appSettings>

    <Settings2>
    <add key="persistent" value="0" />
    <add key="smooth" value="1" />
    </Settings2>

    </configuration>

    I can read/write settings into <appSettings> but don´t know how can i read/write from <Settings2> .... and if i can create new sections like <SettingsN> ... I´m using System.Configuration but only could read/write into the default section named <appSettings>... perhaps someone can give me a hand or point me to the right direction, thanks in advance.

    M H 2 Replies Last reply
    0
    • Z Zeokat

      My config file:

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>

      <appSettings>
      <add key="sunshine" value="125" />
      <add key="moonshine" value="50" />
      <add key="seashine" value="10" />
      </appSettings>

      <Settings2>
      <add key="persistent" value="0" />
      <add key="smooth" value="1" />
      </Settings2>

      </configuration>

      I can read/write settings into <appSettings> but don´t know how can i read/write from <Settings2> .... and if i can create new sections like <SettingsN> ... I´m using System.Configuration but only could read/write into the default section named <appSettings>... perhaps someone can give me a hand or point me to the right direction, thanks in advance.

      M Offline
      M Offline
      Manas Bhardwaj
      wrote on last edited by
      #2

      Zeokat wrote:

      I´m using System.Configuration but only could read/write into the default section named ...

      System.Configuration only exposes methods which for the predefined section (i.e. appsettings). For your purpose, you should rather consider it as a normal xml file and do the read/write.

      Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      Z 1 Reply Last reply
      0
      • M Manas Bhardwaj

        Zeokat wrote:

        I´m using System.Configuration but only could read/write into the default section named ...

        System.Configuration only exposes methods which for the predefined section (i.e. appsettings). For your purpose, you should rather consider it as a normal xml file and do the read/write.

        Manas Bhardwaj Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

        Z Offline
        Z Offline
        Zeokat
        wrote on last edited by
        #3

        Ok, thanks for the informations... I already thougth into write my own config file reader writer, but want to be sure firts that built-in class not allow me do that :)

        1 Reply Last reply
        0
        • Z Zeokat

          My config file:

          <?xml version="1.0" encoding="utf-8"?>
          <configuration>

          <appSettings>
          <add key="sunshine" value="125" />
          <add key="moonshine" value="50" />
          <add key="seashine" value="10" />
          </appSettings>

          <Settings2>
          <add key="persistent" value="0" />
          <add key="smooth" value="1" />
          </Settings2>

          </configuration>

          I can read/write settings into <appSettings> but don´t know how can i read/write from <Settings2> .... and if i can create new sections like <SettingsN> ... I´m using System.Configuration but only could read/write into the default section named <appSettings>... perhaps someone can give me a hand or point me to the right direction, thanks in advance.

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          As modifying configuration files directly can be very dangerous. You should also take a look at How to: Create Custom Configuration Sections[^]. There are also loads of articles, which you might find easier to understand. Just Google for Custom Configuration Section

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          Z 1 Reply Last reply
          0
          • H Henry Minute

            As modifying configuration files directly can be very dangerous. You should also take a look at How to: Create Custom Configuration Sections[^]. There are also loads of articles, which you might find easier to understand. Just Google for Custom Configuration Section

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            Z Offline
            Z Offline
            Zeokat
            wrote on last edited by
            #5

            Thanks Henry Minute, i just googled ypur string and found this Custom Configuration Sections for Lazy Coders[^] Exactly what i was searching... :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups