Rediger

Del via


ClientSettingsProvider Class

Definition

Enables Windows-based applications to retrieve user settings from a Web settings service.

public ref class ClientSettingsProvider : System::Configuration::SettingsProvider, System::Configuration::IApplicationSettingsProvider
public class ClientSettingsProvider : System.Configuration.SettingsProvider, System.Configuration.IApplicationSettingsProvider
[System.Security.SecurityCritical]
public class ClientSettingsProvider : System.Configuration.SettingsProvider, System.Configuration.IApplicationSettingsProvider
type ClientSettingsProvider = class
    inherit SettingsProvider
    interface IApplicationSettingsProvider
[<System.Security.SecurityCritical>]
type ClientSettingsProvider = class
    inherit SettingsProvider
    interface IApplicationSettingsProvider
Public Class ClientSettingsProvider
Inherits SettingsProvider
Implements IApplicationSettingsProvider
Inheritance
ClientSettingsProvider
Attributes
Implements

Examples

The following example code demonstrates how to use this event to display a list of settings that were not successfully saved.

private void AttachSettingsSavedEventHandler()
{
    ((ClientSettingsProvider)Properties.Settings.Default.Providers
        ["System.Web.ClientServices.Providers.ClientSettingsProvider"])
        .SettingsSaved +=
        new EventHandler<SettingsSavedEventArgs>(Form1_SettingsSaved);
}

private void Form1_SettingsSaved(object sender,
    SettingsSavedEventArgs e)
{
    // If any settings were not saved, display a list of them.
    if (e.FailedSettingsList.Count > 0)
    {
        String failedSettings = String.Join(
            Environment.NewLine,
            e.FailedSettingsList.ToArray());

        String message = String.Format("{0}{1}{1}{2}",
            "The following setting(s) were not saved:",
            Environment.NewLine, failedSettings);

        MessageBox.Show(message, "Unable to save settings",
            MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}
Private WithEvents settingsProvider As ClientSettingsProvider = My.Settings _
    .Providers("System.Web.ClientServices.Providers.ClientSettingsProvider")

Private Sub Form1_SettingsSaved(ByVal sender As Object, _
    ByVal e As SettingsSavedEventArgs) _
    Handles settingsProvider.SettingsSaved

    ' If any settings were not saved, display a list of them.
    If e.FailedSettingsList.Count > 0 Then

        Dim failedSettings As String = String.Join( _
            Environment.NewLine, e.FailedSettingsList.ToArray())

        Dim message As String = String.Format("{0}{1}{1}{2}", _
            "The following setting(s) were not saved:", _
            Environment.NewLine, failedSettings)

        MessageBox.Show(message, "Unable to save settings", _
            MessageBoxButtons.OK, MessageBoxIcon.Warning)

    End If

End Sub

Remarks

You can use client application services to retrieve user settings from an existing Web settings service by configuring your application to use the ClientSettingsProvider class. After configuration, you can get and set user settings through an application settings class derived from ApplicationSettingsBase and configured to use the ClientSettingsProvider class. You can use Visual Studio to generate a Settings class for your project (accessed as Properties.Settings.Default in C# and My.Settings in Visual Basic). For more information about application settings, see Application Settings Overview.

You can retrieve the current ClientSettingsProvider through the ApplicationSettingsBase.Providers property using the fully-qualified ClientSettingsProvider class name as a key. You can also retrieve the provider through the SettingsLoadedEventArgs.Provider property when you handle the ApplicationSettingsBase.SettingsLoaded event.

Note

This class contains a SecurityCriticalAttribute at the class level that applies to all members of the class. A run-time exception is thrown if the immediate caller is security-transparent or partially trusted. For more information about security-critical types and members, see Security-Transparent Code, Level 2.

Note

This class contains an inheritance demand at the class level that applies to all members. A SecurityException is thrown when the derived class does not have full-trust permission. For details about security demands, see Link Demands and Inheritance Demands.

Constructors

ClientSettingsProvider()

Initializes a new instance of the ClientSettingsProvider class.

Properties

ApplicationName

This property is not used by this class.

Description

Gets a brief, friendly description suitable for display in administrative tools or other user interfaces (UIs).

(Inherited from ProviderBase)
Name

Gets the friendly name used to refer to the provider during configuration.

(Inherited from ProviderBase)
ServiceUri

Gets or sets the Web settings service location.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetPreviousVersion(SettingsContext, SettingsProperty)

Gets the previous version of the specified property.

GetPropertyMetadata(String)

Gets a collection of metadata for all properties retrieved from the specified Web settings service.

GetPropertyValues(SettingsContext, SettingsPropertyCollection)

Returns the collection of settings property values for the specified application instance and settings property group.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
Initialize(String, NameValueCollection)

Initializes the provider.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
Reset(SettingsContext)

Resets all user settings to their default values.

SetPropertyValues(SettingsContext, SettingsPropertyValueCollection)

Sets the values of the specified group of property settings.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
Upgrade(SettingsContext, SettingsPropertyCollection)

This method is not used by this class.

Events

SettingsSaved

Occurs after the settings provider attempts to save the property values to the Web settings service.

Applies to

See also