Take the 2-minute tour ×

I am in the process of writing a service using C# and I need to store a list of strings within the app.config file. I have 161 of these.

How can I store this information in the app.config file? There must be a way, because these are strongly typed values and thus I'm supposed to easily use any valid .NET type in the code to access them!

I want to avoid having one value that uses a comma-separated list for obvious performance issues.

share|improve this question
How would a comma-separated list impact performance? I've used comma-delimited string in config files before and not noticed any performance issue. –  Tim Oct 24 '11 at 7:31
@Tim - I agree that performance if probably not the driver for this, but for 161 items, a comma separated list is not the most elegant solution in your app.config file. Given that app.config is XML and will be de-serialized anyway, it is much nicer to store your data in XML inside it. –  Steve Fenton Oct 24 '11 at 7:43

2 Answers 2

up vote 9 down vote accepted

I use Microsoft’s Visual Studio 2010.

  1. In Solution Explorer, expand the Properties node of your project.

  2. In Solution Explorer, double-click the .settings file in which you want to add a new setting. The default name for this file is Settings.settings.

  3. In Settings Designer, set the Name, Type, Scope, and Value for your setting. Each row represents a single setting.

  4. The Type that you need is System.Collections.Specialized.StringCollection. This can be located after clicking Browse at the end of the DropDownList that appears when you click to set the Type.

  5. Click on the button that appears towards the end of the Value TextBox.

  6. Type in your strings, one-by-one, in the dialog that appears.

This is how it goes.

share|improve this answer

There is a good article about storing lists (or any custom object) in your app.config files in Best Way Of Saving Lists in App.Config

Essentially, you create an object that represents the data.

public class MyConfig
    public string[] myList;
    public string someOtherValueIfYouWant;

And write a config handler for it...

public class ConfigSectionHandler : IConfigurationSectionHandler
    public const string SECTION_NAME = "MyConfig";
        string szConfig = section.SelectSingleNode("//MyConfig").OuterXml;
        MyConfig retConf = null;

        if (szConfig != string.Empty || szConfig != null)
            XmlSerializer xsw = new XmlSerializer(typeof(MyConfig));
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(szConfig));
            ms.Position = 0;
            retConf = (MyConfig)xsw.DeSerialize(ms);
        return retConf;


And this allows you to put the following XML in your app.config file...

Tell app.config about your cool config section

    <section name="MyConfig" type="ConfigSectionHandler,someAssembly" />

And then add your config section...

    <myList>First one</myList>
    <myList>Second one</myList>
    <myList>Keep going</myList>
    <myList>And so on</myList>
    <someOtherValueIfYouWant>some non array config</someOtherValueIfYouWant>
share|improve this answer
WARNING: This topic uses the System.Configuration.IConfigurationSectionHandler interface, which has been deprecated in the .NET Framework version 2.0. For an example that uses the System.Configuration.ConfigurationSection class, see How to: Create Custom Configuration Sections Using ConfigurationSection (msdn.microsoft.com/en-us/library/2tw134k3(v=vs.100).aspx) –  woohoo Mar 14 at 13:37

Your Answer


