다음을 통해 공유


<appSettings> Element

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

<configuration>
**      <appSettings>**

<appSettings file="relative file name">
</appSettings>

Optional Attribute

Attribute Description
file 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 would be 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.

Note that the runtime ignores the attribute if the specified file can not be found.

Child Elements

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

Remarks

The <appSettings> element stores custom application configuration information such as database connection strings, file paths, XML Web service URLs, or any information stored in an application's .ini file. The key/value pairs specified in the <appSettings> element can be accessed in code using the System.Configuration.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 <appSettings> rather than <configuration> as the root node. The following code is correct for a configuration file specified with the file attribute:

            <?xml version="1.0" encoding="utf-8" ?>
            <appSettings>
            <add key="Application1" value="MyApplication1" />
            <add key="Setting1" value="MySetting" />
            </appSettings>

Example

The following example shows how to define a custom application setting in a configuration file.

<configuration>
    <appSettings>
        <add key="Application Name" 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

Configuration Sections Schema | Configuration Section Settings