.NET Framework Class Library
ConfigurationManager.AppSettings Property

Note: This property is new in the .NET Framework version 2.0.

Gets the AppSettingsSection data for the current application's default configuration.

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

Syntax

Visual Basic (Declaration)
Public Shared ReadOnly Property AppSettings As NameValueCollection
Visual Basic (Usage)
Dim value As NameValueCollection

value = ConfigurationManager.AppSettings
C#
public static NameValueCollection AppSettings { get; 
C++
public:
static property NameValueCollection^ AppSettings {
    NameValueCollection^ get ();
J#
/** @property */
public static NameValueCollection get_AppSettings ()
JScript
public static function get AppSettings () : NameValueCollection

Property Value

Returns a NameValueCollection object containing the contents of the AppSettingsSection object for the current application's default configuration.
Exceptions

Exception typeCondition

ConfigurationErrorsException

Could not retrieve a NameValueCollection object with the application settings data.

Remarks

A AppSettingsSection object contains the contents of the configuration file's appSettings section.

Example

The following code example shows how to get a named application setting using the AppSettings property.

Visual Basic
' Get appSettings.
Shared Sub GetAppSettings()
   ' Get the appSettings.
     Dim appSettings As NameValueCollection = _
     ConfigurationManager.AppSettings
   
   ' Get the collection enumerator.
     Dim appSettingsEnum As IEnumerator = _
     appSettings.Keys.GetEnumerator()
   
   ' Loop through the collection and
   ' display the appSettings key, value pairs.
   Dim i As Integer = 0
   While appSettingsEnum.MoveNext()
      Dim key As String = appSettings.Keys(i)
         Console.WriteLine("Name: {0 Value: {1", _
         key, appSettings(key))
      i += 1
   End While
End Sub 'GetAppSettings
 
C#
// Get appSettings.
static void GetAppSettings()
{
    // Get the appSettings.
    NameValueCollection appSettings =
         ConfigurationManager.AppSettings;
    
    // Get the collection enumerator.
    IEnumerator appSettingsEnum =
        appSettings.Keys.GetEnumerator();

    // Loop through the collection and
    // display the appSettings key, value pairs.
    int i = 0;
    Console.WriteLine("App settings.");
    while (appSettingsEnum.MoveNext())
    {
        string key = appSettings.Keys[i];
        Console.WriteLine("Name: {0 Value: {1",
        key, appSettings[key]);
        i += 1;
    

Platforms

Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information

.NET Framework

Supported in: 2.0
See Also

Tags :


Page view tracker