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. LINQ
  4. Using sectiongroup tag in app.config ( C# 2008)

Using sectiongroup tag in app.config ( C# 2008)

Scheduled Pinned Locked Moved LINQ
csharpcomtutorialworkspace
2 Posts 2 Posters 3 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.
  • J Offline
    J Offline
    Jitendra Kumar Goyal
    wrote on last edited by
    #1

    Hi all i am trying to create and access sections in a config file.e.g I've multiple mailboxes & I want to store them in a config file. Below is give the code for my config file. __________________________________________________ <configuration> <configSections> <sectionGroup name="MailBoxesGroup"> <<section name="MailBoxes" type="System.Configuration.NameValueSectionHandler" /> </sectionGroup> > </configSections> <MailBoxesGroup> <MailBoxes> <add key="MailBox" value="user1@gmail.com" /> <add key="Password" value="pass" /> <add key="MailBox" value="user2@gmail.com" /> <add key="Password" value="pass2" /> <add key="OverridePollingSeconds" value="50" /> <add key="ExtentedLogging" value="False" /> </MailBoxes> </configuration> ___________________________________________________________ While trying to retrieve the values, it is able to get only the last value. The code i am using to read this config file is as below

    NameValueCollection mailBoxes = (NameValueCollection)ConfigurationSettings.GetConfig("MailBoxesGroup/MailBoxes");

                Hashtable MailBoxes = new Hashtable();
                foreach (string mailBox in mailBoxes)
                {
    
                    MailBoxes.Add(mailBoxes\["MailBox"\], mailBoxes\["Password"\]);
    
                }
    

    Please suggest how to use sections. Thanks in advance.

    modified on Tuesday, September 2, 2008 12:20 AM

    H 1 Reply Last reply
    0
    • J Jitendra Kumar Goyal

      Hi all i am trying to create and access sections in a config file.e.g I've multiple mailboxes & I want to store them in a config file. Below is give the code for my config file. __________________________________________________ <configuration> <configSections> <sectionGroup name="MailBoxesGroup"> <<section name="MailBoxes" type="System.Configuration.NameValueSectionHandler" /> </sectionGroup> > </configSections> <MailBoxesGroup> <MailBoxes> <add key="MailBox" value="user1@gmail.com" /> <add key="Password" value="pass" /> <add key="MailBox" value="user2@gmail.com" /> <add key="Password" value="pass2" /> <add key="OverridePollingSeconds" value="50" /> <add key="ExtentedLogging" value="False" /> </MailBoxes> </configuration> ___________________________________________________________ While trying to retrieve the values, it is able to get only the last value. The code i am using to read this config file is as below

      NameValueCollection mailBoxes = (NameValueCollection)ConfigurationSettings.GetConfig("MailBoxesGroup/MailBoxes");

                  Hashtable MailBoxes = new Hashtable();
                  foreach (string mailBox in mailBoxes)
                  {
      
                      MailBoxes.Add(mailBoxes\["MailBox"\], mailBoxes\["Password"\]);
      
                  }
      

      Please suggest how to use sections. Thanks in advance.

      modified on Tuesday, September 2, 2008 12:20 AM

      H Offline
      H Offline
      Howard Richards
      wrote on last edited by
      #2

      http://www.codeproject.com/KB/aspnet/ConfigSections.aspx[^]

      'Howard

      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