Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 2.0
 Save Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
.NET Framework Class Library
ApplicationSettingsBase.Save Method

Note: This method is new in the .NET Framework version 2.0.

Stores the current values of the application settings properties.

Namespace: System.Configuration
Assembly: System (in system.dll)

Visual Basic (Declaration)
Public Overrides Sub Save
Visual Basic (Usage)
Dim instance As ApplicationSettingsBase

instance.Save
C#
public override void Save ()
C++
public:
virtual void Save () override
J#
public void Save ()
JScript
public override function Save ()

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.

NoteImportant:

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.

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.Save();

C++
private:
    void AppSettingsForm_FormClosing(Object^ sender,
        FormClosingEventArgs^ e)
    {
        //Synchronize manual associations first.
        formSettings->FormText = this->Text + '.';
        formSettings->Save();
    

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker