C# Properties wont save

208 Views Asked by At

I want to save settings between two sessions.

I change the value, save it, close the program and its still the old one... WHY?

int test = Properties.Settings.Default.mode;
        System.Console.WriteLine(test);
        Properties.Settings.Default.mode = 1;
        Properties.Settings.Default.Save();
        test = Properties.Settings.Default.mode;
        System.Console.WriteLine(test);

XML:

<userSettings>
    <PyControl.Properties.Settings>
        <setting name="mode" serializeAs="String">
            <value>0</value>
        </setting>
    </PyControl.Properties.Settings>
</userSettings>
1

There are 1 best solutions below

3
Tide Gu On

Probably you were finding the settings file in wrong place? It isn't in your bin folder.

Your application will have a settings folder under %userprofile%\appdata\local or %userprofile%\Local Settings\Application Data depending on which version of Windows you're running, for settings that are user specific. If you store settings for all users, then they'll be in the corresponding folder under C:\users or C:\Documents and Settings for all user profiles (ex: C:\users\public\appdata\local).

Ref: Where are the Properties.Settings.Default stored?

Edit:

Assume if you're NOT using Windows IoT, try ~/.config/{AppName}/user.config? I don't write C# on RPi but above link mentioned this folder. -- If not here, I'm sorry that I can't offer further help :(