Read settings file into NameValueCollection

Posted on 2007-09-28
Last Modified: 2013-11-07
Is there a way to read settings from a .settings file into NameValueCollection without having to parse XML? I know about Properties for the current application, but that doesn't apply in this case since I need something where I could specify the settings file anywhere on the disk and get the settings.

Question by:gromul
    LVL 21

    Expert Comment

    Have you thought about creating a custom object and serializing it into a XML file so as to get the basic skeleton needed and then adding on to it and using a deserializer to convert it back to the custom class?
    LVL 21

    Expert Comment

    U can use the above solution if u were not particular with using only the SETTINGS file

    Author Comment

    I got it working with the following format using the code from

    <?xml version="1.0" encoding="utf-8" ?>
          <add key="Key1" value="Value1" />

    However this is not exactly what I wanted, as I know have to maintain my own config files in addition to the settings file already there.

    I would appreciate any hints in what I would need to do to process a file like this:

    <?xml version="1.0" encoding="utf-8" ?>
          <sectionGroup name="applicationSettings" type="System.Configuration.applicationSettingsGroup, System, Version=, Culture=neutral, PublicKeyToken=a77a5c561034e089" >
             <section name="MyProject.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=, Culture=neutral, PublicKeyToken=a77a5c561034e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
             <setting name="Key1" serializeAs="String">
    LVL 21

    Accepted Solution

    There is no straight or easy way a simple name value collection can represent a multi level deep hierrarchial file with your custom sections. For that you will have to write a class similar to the file, read the values into the properties.

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    In my previous article ( we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now