ApplicationSettingsBase.Save Method

Definition

Stores the current values of the application settings properties.

C#
public override void Save();

Examples

The following code example shows the Save method being called from the Closing event handler for the primary form. This method also appends an extra period to the settings property that is associated with the form's Text property.

The full code example is listed in the ApplicationSettingsBase class overview.

C#
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    //Synchronize manual associations first.
    frmSettings1.FormText = this.Text + '.';
    frmSettings1.FormSize = this.Size;
    frmSettings1.Save();
}

Remarks

The Save method writes the current value of each settings property to its associated data store. For each property, this method calls the SetPropertyValues method on the associated settings provider.

This method differs from the base class implementation in that it raises the SettingsSaving event before the values are written.

If the only settings defined are application-scoped settings, Save will have no effect and return no error if called with the default LocalFileSettingsProvider. LocalFileSettingsProvider only saves user-scoped settings.

Important

There is no corresponding Load method because the values of application settings are automatically loaded during wrapper class initialization. In contrast, these values are not automatically saved when an application ends. Therefore, you must explicitly call the Save method to persist the current values of the application settings. This is typically performed in the Closing event handler of the primary or containing Form.

Applies to

Product Versions
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also