<appSettings> element for <configuration>

Contains custom application settings. This is a predefined configuration section provided by the .NET Framework.

<configuration>
  <appSettings>

Syntax

<appSettings>
  <!-- Elements to add, clear, or remove configuration settings -->
</appSettings>

Attribute

Description
file Optional attribute.

Specifies a relative path to an external file containing custom application configuration settings. The specified file contains the same kind of settings that are specified in the <add>, <remove>, and <clear> elements and uses the same key/value pair format as those elements.

The path specified is relative to the main configuration file. For a Windows Forms application, this is the binary folder (such as /bin/debug), not the location of the application configuration file. For Web Forms applications, the path is relative to the application root, where the web.config file is located.

The runtime ignores the attribute if the specified file can't be found.

Parent element

Description
<configuration> Element The root element in every configuration file used by the common language runtime and .NET Framework applications.

Child elements

Description
<add> Adds a custom application setting.
<clear> Clears all previously defined application settings.
<remove> Removes a previously defined application setting.

Remarks

The <appSettings> element stores custom application configuration information, such as database connection strings, file paths, XML Web service URLs, or any other custom configuration information for an application. The key/value pairs specified in the <appSettings> element are accessed in code using the ConfigurationSettings class.

You can use the file attribute in the <appSettings> element of the Web.config and application configuration files. This attribute specifies a configuration file that provides additional settings or overrides the settings specified in the <appSettings> element. The file attribute can be used in source control team development scenarios, such as when a user wants to override the project settings specified in an application configuration file.

Configuration files specified by the file attribute must have a root node of <appSettings> rather than <configuration>.

Example

The following example shows an external application settings file (custom.config) that defines a custom application setting:

<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
  <add key="MyCustomSetting" value="MyCustomSettingValue" />
</appSettings>

The following example shows an application configuration file that consumes the setting in the external settings file and sets an application setting of its own:

<configuration>
  <appSettings file="custom.config">
    <add key="ApplicationName" value="MyApplication" />
  </appSettings>
</configuration>

Configuration file

This element can be used in the application configuration file, machine configuration file (Machine.config), and Web.config files that are not at the application directory level.

See also