Question

I am using the Properties.Settings class to save the application settings. I would like to know, once I deploy in the client system, whether the settings would be saved across application restart and system restart.

Consider the scenario :

Once the application is deployed, the user would save the Mobile Number through a UI as

Phone : 1xxxx - 45678

Now, I would save the Phone number as

 Properties.Settings.Default.ClientPhone = this.PhoneText.Text;
 Properties.Settings.Default.Save();

Am I understand, that the phone number would be saved in the application across app.restarts and reboots?

Was it helpful?

Solution

This is the difference about application and user settings. Application settings are read only. User settings are stored permanently on a per-user basis. Your code is exactly what it takes to change and save a user setting.

Please note: As they are called "user settings", they will be stored separately for every user on the machine! You can not, using the default .NET settings mechanism, create changeable settings that are the same for all users.

Do not re-invent the wheel! Use the .NET settings mechanism - you're doing it right in your example :-)

OTHER TIPS

This will work fine, however one thing to bear in mind is that if you install a new version of the program, it will "lose" the old settings (because the settings are specific to a particular version of your program). (By "version" I mean the AssemblyVersion)

Fortunately, you can deal with this by calling the following function at or near the beginning of Main(). For this to work you will need to add a new boolean setting property called NeedSettingsUpgrade and default it to 'true':

/// <summary>Upgrades the application settings, if required.</summary>

private static void upgradeProgramSettingsIfNecessary()
{                                                        
    // Application settings are stored in a subfolder named after the full #.#.#.# version
    // number of the program. This means that when a new version of the program is installed,
    // the old settings will not be available.
    //
    // Fortunately, there's a method called Upgrade() that you can call to upgrade the settings
    // from the old to the new folder.
    //
    // We control when to do this by having a boolean setting called 'NeedSettingsUpgrade' which
    // is defaulted to true. Therefore, the first time a new version of this program is run, it
    // will have its default value of true.
    //
    // This will cause the code below to call "Upgrade()" which copies the old settings to the new.
    // It then sets "NeedSettingsUpgrade" to false so the upgrade won't be done the next time.

    if (Settings.Default.NeedSettingsUpgrade)
    {
        Settings.Default.Upgrade();
        Settings.Default.NeedSettingsUpgrade = false;
    }
}

A quick google should have done it for you.

Yes they will according to msdn: .NET allows you to create and access values (settings) that are persisted between application execution sessions.

http://msdn.microsoft.com/en-us/library/aa730869(v=vs.80).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top