Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 AppSettings Property
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
WebConfigurationManager..::.AppSettings Property

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

Namespace:  System.Web.Configuration
Assembly:  System.Web (in System.Web.dll)
Visual Basic (Declaration)
Public Shared ReadOnly Property AppSettings As NameValueCollection
Visual Basic (Usage)
Dim value As NameValueCollection

value = WebConfigurationManager.AppSettings
C#
public static NameValueCollection AppSettings { get; }
Visual C++
public:
static property NameValueCollection^ AppSettings {
    NameValueCollection^ get ();
}
JScript
public static function get AppSettings () : NameValueCollection

Property Value

Type: System.Collections.Specialized..::.NameValueCollection
A NameValueCollection object that contains the AppSettingsSection object for the current Web application's default configuration.
ExceptionCondition
ConfigurationErrorsException

A valid NameValueCollection object could not be retrieved with the application settings data.

An AppSettingsSection object contains the configuration file's <appSettings> section.

The following example shows how to access configuration information with the AppSettings method.

Visual Basic
' Show the use of AppSettings. 
' It gets the section from the configuration 
' file located at the application current level. 
Shared Sub GetAppSettings()

   ' Get the appSettings key,value pairs collection.
     Dim appSettings As NameValueCollection = _
     WebConfigurationManager.AppSettings

   ' Get the collection enumerator.
     Dim appSettingsEnum As IEnumerator = _
     appSettings.GetEnumerator()

   ' Loop through the collection and 
   ' display the appSettings key, value pairs.
   Dim i As Integer = 0
   Console.WriteLine("[Display appSettings]")
   While appSettingsEnum.MoveNext()
      Dim key As String = appSettings.AllKeys(i)
         Console.WriteLine("Key: {0} Value: {1}", _
         key, appSettings(key))
      i += 1
   End While

   Console.WriteLine()
End Sub 'GetAppSettings


C#
// Show the use of AppSettings. 
// It gets the section from the configuration 
// file located at the application current level. 
static void GetAppSettings()
{

    // Get the appSettings key,value pairs collection.
    NameValueCollection appSettings =
        WebConfigurationManager.AppSettings
        as NameValueCollection;

    // Get the collection enumerator.
    IEnumerator appSettingsEnum =
        appSettings.GetEnumerator();

    // Loop through the collection and 
    // display the appSettings key, value pairs.
    int i = 0;
    Console.WriteLine("[Display appSettings]");
    while (appSettingsEnum.MoveNext())
    {
        string key = appSettings.AllKeys[i].ToString();
        Console.WriteLine("Key: {0} Value: {1}",
        key, appSettings[key]);
        i += 1;
    }

    Console.WriteLine();
}

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2010 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker