Nanji Mange
Nanji Mange

Reputation: 2265

How to keep Settings details in Visual Studio application?

I use Local setting to store username and password of application user.

Purpose: When user click on Remember me check, it store in local. When user restart application, it get from local setting and show.

MyApplication.Properties.Settings.Default.UserName = "john"; //get from login form MyApplication.Properties.Settings.Default.Password = "jonh@123"; //get from login form

This is working fine if application run continuously. But If I install upgrade version of the application, it behaves incorrectly. This MyApplication.Properties.Settings.Default.UserName returns older user name.

If I again install another upgrade version, it returns any other user name that I have used before.

Can anybody suggest what I am missing here?

Upvotes: 0

Views: 72

Answers (1)

Barry O'Kane
Barry O'Kane

Reputation: 1187

Try this. Create a setting called UserSettingsUpgradeRequired, set it's value to true, and check it at startup. If it's true then this is the first run of the new version so call Settings.Default.Upgrade();

private static void CheckUserSettingsUpgradeRequired()
{
    if (Settings.Default.UserSettingsUpgradeRequired)
    {
        Settings.Default.Upgrade();
        Settings.Default.UserSettingsUpgradeRequired = false;
        Settings.Default.Save();
    }
}

Upvotes: 2

Related Questions