LocalFileSettingsProvider 类


为应用程序设置类提供持久性存储。Provides persistence for application settings classes.

public ref class LocalFileSettingsProvider : System::Configuration::SettingsProvider, System::Configuration::IApplicationSettingsProvider
public class LocalFileSettingsProvider : System.Configuration.SettingsProvider, System.Configuration.IApplicationSettingsProvider
type LocalFileSettingsProvider = class
    inherit SettingsProvider
    interface IApplicationSettingsProvider
Public Class LocalFileSettingsProvider
Inherits SettingsProvider
Implements IApplicationSettingsProvider


设置提供程序定义用于存储应用程序设置体系结构中使用的配置数据的机制。Setting providers define a mechanism for storing configuration data used in the application settings architecture. .NET Framework.NET Framework包含一个默认设置提供程序,该提供程序 LocalFileSettingsProvider 将配置数据存储到本地文件系统。The .NET Framework.NET Framework contains a single default settings provider, LocalFileSettingsProvider, which stores configuration data to the local file system. 应用程序设置属性或一组属性通过使用关联到特定的设置提供程序 SettingsProviderAttributeAn application settings property or group of properties are associated to a specific settings provider through the use of the SettingsProviderAttribute.

通常,客户端程序不会显式访问此类;相反,当需要其服务时,应用程序设置体系结构会自动调用相应的设置提供程序。Typically, the client program does not explicitly access this class; rather, the application settings architecture automatically invokes the appropriate settings provider when its services are required. 例如,许多成员将 ApplicationSettingsBase 其工作委托给关联的设置提供程序。For example, many of the members of ApplicationSettingsBase delegate their work to the associated settings provider.

LocalFileSettingsProvider 将设置保存到扩展名为的配置文件中 .configLocalFileSettingsProvider persists settings to configuration files that have the extension .config. 配置文件的内容结构化为 XML 文档。The contents of configuration files are structured as XML documents. 配置数据将分别存储为 <applicationSettings> 或节组中的元素,具体取决于应用程序级别或用户级别的设置是否作用域 <userSettings>Depending on whether the setting is scoped at either the application-level or user-level, the configuration data is stored as elements within an <applicationSettings> or a <userSettings> section group, respectively. 每个分区组都由相应的 AppSettingsSection 或分别表示 ClientSettingsSectionEach of these section groups is represented by a corresponding AppSettingsSection or ClientSettingsSection, respectively. 每个节对象均由配置节处理程序所拥有和管理,该处理程序是类型的对象 IConfigurationSectionHandlerEach section object is owned and administered by a configuration section handler, which is an object of type IConfigurationSectionHandler.

应用程序范围的设置和默认用户范围设置存储在名为的文件中 application.exe.config ,该文件在与可执行文件相同的目录中创建。Application-scoped settings and the default user-scoped settings are stored in a file named application.exe.config, which is created in the same directory as the executable file. 应用程序配置设置为只读。Application configuration settings are read-only. 特定用户数据存储在名为的文件中 user.config ,该文件存储在用户的主目录下。Specific user data is stored in a file named user.config, stored under the user's home directory. 如果启用了漫游配置文件,则可以存在两个版本的用户配置文件。If roaming profiles are enabled, two versions of the user configuration file could exist. 在这种情况下,漫游版本中的条目优先于本地用户配置文件中的重复项。In such a case, the entries in the roaming version take precedence over duplicated entries in the local user configuration file.

有关应用程序设置的详细信息,请参阅 Windows 窗体的应用程序设置For more information about application settings, see Application Settings for Windows Forms.



初始化 LocalFileSettingsProvider 类的新实例。Initializes a new instance of the LocalFileSettingsProvider class.



获取或设置当前运行的应用程序的名称。Gets or sets the name of the currently running application.


获取一条简短的易懂描述,它适合在管理工具或其他用户界面 (UI) 中显示。Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(继承自 ProviderBase)

获得一个友好名称,用于在配置过程中引用提供程序。Gets the friendly name used to refer to the provider during configuration.

(继承自 ProviderBase)



确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetPreviousVersion(SettingsContext, SettingsProperty)

返回同一应用程序的早期版本的命名设置属性的值。Returns the value of the named settings property for the previous version of the same application.

GetPropertyValues(SettingsContext, SettingsPropertyCollection)

为指定的应用程序实例和设置属性组返回设置属性值的集合。Returns the collection of setting property values for the specified application instance and settings property group.


获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
Initialize(String, NameValueCollection)

初始化提供程序。Initializes the provider.


创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

将与指定的应用程序关联的所有应用程序设置属性重置为其默认值。Resets all application settings properties associated with the specified application to their default values.

SetPropertyValues(SettingsContext, SettingsPropertyValueCollection)

设置指定的属性设置组的值。Sets the values of the specified group of property settings.


返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)
Upgrade(SettingsContext, SettingsPropertyCollection)

尝试从相同应用程序的早期版本迁移以前的用户范围设置。Attempts to migrate previous user-scoped settings from a previous version of the same application.