Zero
Zero

Reputation: 330

User settings not loading/saving

I am having this problem with loading/saving application settings. I am saving the settings like this

    string value = "test";
    Properties.Settings.Default.test1 = value;
    Properties.Settings.Default.Save();

It works if I load the settings while the program is still running but whenever I close the application and start it up again the saved value is gone.

    string savedValue = Properties.Settings.Default.test1;

I have tried Refreshing after saving but that does not seem to help.

However I found where the settings are stored (Appdata\Local) and the value indeed shows up in there but it does not get loaded.

Upvotes: 1

Views: 4914

Answers (2)

Archana K V
Archana K V

Reputation: 1

I am a WPF Developer , so am sure that the Properties.Settings definitely save while use

Properties.Settings.Default.Save();

Or

Properties.Settings settings= new Properties.Settings();
settings.YourParameter=true;
settings.Save();

If you don't get the updated value in settings then you first use settings=new Properties.Settings(); You will be definitely get new result.

Upvotes: 0

Micke
Micke

Reputation: 2309

This is how it is done. If your code doesn't work, try creating an MCVE to enable further debugging.

namespace ConsoleApplication5
{
    using System;

    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("This should be blank on first run, but not on subsequent: {0}", Properties.Settings.Default.test1);

            string value = "test";

            Properties.Settings.Default.test1 = value;

            Properties.Settings.Default.Save();
        }
    }
}

Pass #1:

This should be blank on first run, but not on subsequent:
Press any key to continue . . .

Pass #2:

This should be blank on first run, but not on subsequent: test
Press any key to continue . . .

Upvotes: 2

Related Questions