This documentation is archived and is not being maintained.

AppSettingsReader Class

Provides a method for reading values of a particular type from the configuration.

Namespace: System.Configuration
Assembly: System (in system.dll)

public class AppSettingsReader
public class AppSettingsReader
public class AppSettingsReader
Not applicable.

The following example creates a configuration file that contains the <appSettings> section, and then uses the AppSettingsReader to read the settings just generated.

using System;
using System.Collections.Specialized;
using System.Configuration;

namespace AspNet.Samples
    class UsingAppSettingsSection
        static void ShowAppSettings()

            AppSettingsReader reader = 
                new AppSettingsReader();

            NameValueCollection appStgs = 

            string[] names = 
            String value = String.Empty;

            for (int i = 0; i < appStgs.Count; i++)

                string key = names[i];

                value = (String)reader.GetValue(key, value.GetType());

                Console.WriteLine("#{0} Name: {1} Value: {2}",
                  i, key, value);


        static void Main(string[] args)
            // Get the count of the Application Settings.
            int appStgCnt = ConfigurationManager.AppSettings.Count;
            string asName = "AppStg" + appStgCnt.ToString();

            // Get the configuration file.
            System.Configuration.Configuration config =
            // Add an Application setting.
              DateTime.Now.ToLongDateString() + " " +
            // Save the configuration file.
            // Force a reload of a changed section.

            Console.WriteLine("Application Settings:");

            Console.WriteLine("Press 'Enter' to exit.");

The following example demonstrates a configuration file used by the previous example.

<?xml version="1.0" encoding="utf-8"?>
        <add key="AppStg0" value="Thursday, December 01, 2005 12:53:56 PM" />
        <add key="AppStg1" value="Thursday, December 01, 2005 12:54:15 PM" />
        <add key="AppStg2" value="Thursday, December 01, 2005 1:37:22 PM" />


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0