Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 162613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:25:20+00:00 2026-05-11T11:25:20+00:00

I am trying to access settings in my config file, which is a series

  • 0

I am trying to access settings in my config file, which is a series of xml elements listed as such:

<databases> <database name='DatabaseOne' Value='[value]' /> <database name='DatabaseTwo' Value='[value]' /> </databases> 

Now I want to access it. I have set up classes like so:

Public Class DatabaseConfigurationHandler     Inherits ConfigurationSection      <ConfigurationProperty('Databases', IsDefaultCollection:=True)> _    Public ReadOnly Property Databases() As DatabaseCollection         Get             Return CType(Me('Databases'), DatabaseCollection)         End Get     End Property End Class  Public Class DatabaseCollection     Inherits ConfigurationElementCollection      Protected Overloads Overrides Function CreateNewElement() As ConfigurationElement         Return (New Database())     End Function      Protected Overloads Overrides Function GetElementKey(ByVal element As ConfigurationElement) As Object         Return (CType(element, Database).DatabaseName)     End Function  End Class  Public Class Database     Inherits ConfigurationElement      <ConfigurationProperty('name', IsKey:=True, IsRequired:=True)> _        Public Property DatabaseName() As String         Get             Return Me('name').ToString()         End Get         Set(ByVal Value As String)             Me('name') = Value         End Set     End Property       <ConfigurationProperty('value', IsRequired:=True)> _ Public Property DatabaseValue() As String         Get             Return Me('value').ToString()         End Get         Set(ByVal Value As String)             Me('value') = Value         End Set     End Property  End Class 

I want to be able get the element by it’s name and return the value but I can’t see to do that:

Dim config As New DatabaseConfigurationHandler                 config = System.Configuration.ConfigurationManager.GetSection('databases/database')                 Return config.Databases('DatabaseOne') 

Am I missing some code, what am I doing wrong? Any other errors in the above?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:25:21+00:00Added an answer on May 11, 2026 at 11:25 am

    Here’s a cut and paste from something very similar I did a few days ago.

    Config:

      <ListConfigurations>     <lists>       <add Name='blah' EndpointConfigurationName='blah' ListName='blah' ConnectionString='blah' TableName='blah' FieldsCsv='blah' DbFieldsCsv='blah'/>       <add Name='blah2' EndpointConfigurationName='blah' ListName='blah' ConnectionString='blah' TableName='blah' FieldsCsv='blah' DbFieldsCsv='blah'/>     </lists>   </ListConfigurations> 

    Config section C#:

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration;  namespace App {     /// <summary>     /// Individual list configuration     /// </summary>     class ListConfiguration : ConfigurationElement     {         [ConfigurationProperty('Name', IsKey = true, IsRequired = true)]         public string Name         {             get { return (string)this['Name']; }         }          [ConfigurationProperty('EndpointConfigurationName', IsRequired = true)]         public string EndpointConfigurationName         {             get { return (string)this['EndpointConfigurationName']; }         }          [ConfigurationProperty('ListName', IsRequired = true)]         public string ListName         {             get { return (string)this['ListName']; }         }          [ConfigurationProperty('ConnectionString', IsRequired = true)]         public string ConnectionString         {             get { return (string)this['ConnectionString']; }         }          [ConfigurationProperty('TableName', IsRequired = true)]         public string TableName         {             get { return (string)this['TableName']; }         }          [ConfigurationProperty('FieldsCsv', IsRequired = true)]         public string FieldsCsv         {             get { return (string)this['FieldsCsv']; }         }          [ConfigurationProperty('DbFieldsCsv', IsRequired = true)]         public string DbFieldsCsv         {             get { return (string)this['DbFieldsCsv']; }         }     }      /// <summary>     /// Collection of list configs     /// </summary>     class ListConfigurationCollection : ConfigurationElementCollection     {         protected override ConfigurationElement CreateNewElement()         {             return new ListConfiguration();         }          protected override object GetElementKey(ConfigurationElement element)         {             return ((ListConfiguration)element).Name;         }     }      /// <summary>     /// Config section     /// </summary>     class ListConfigurationSection : ConfigurationSection     {         [ConfigurationProperty('lists')]         public ListConfigurationCollection Lists         {             get { return (ListConfigurationCollection)this['lists']; }         }     } } 

    And the code to pick it up from the main app:

    ListConfigurationSection configSection = null; try {     configSection = ConfigurationManager.GetSection('ListConfigurations') as ListConfigurationSection; } catch (System.Configuration.ConfigurationErrorsException) { } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to access a file for xml parsing with this: InputStream inputStream
I am trying to access maven repository from behind proxy. I configured settings.xml correctly
When trying to access the database, I am unable to access the column. I
Im trying to access a Sql CE 2005 database on a windows mobile device
I am trying to access all the data from database listOfFolder table folder and
Hi I'm trying to access a WCF service which returns a JSON Array using
I am trying to use a config file in my C# console application. I
I'm trying to access a model for global system settings. It should be loaded
I'm trying to work with a settings.settings file in my project. There are values
I'm trying to update a value in my app.config file using the code below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.