Skip to content

XML Setting don't save

Michael

Asked Jun 5, 2008, 4:01 AM EDT5 answers
Share
LinkedInX
okay this is driving me nut and it is probably such a simple solution but for the life of me i can't figure out what i'm doing wrong

okay i have the following code
Properties.Settings.Default.ShowAdvanced = this.tsbAdvancedMode.Checked;
Properties.Settings.Default.Save();

now i ththought that this was the way to save a setting to the config file, but it didn't.

to test it i did this

MessageBox.Show(Properties.Settings.Default.ShowAdvanced.ToString());
Properties.Settings.Default.ShowAdvanced = this.tsbAdvancedMode.Checked;
MessageBox.Show(Properties.Settings.Default.ShowAdvanced.ToString());
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
MessageBox.Show(Properties.Settings.Default.ShowAdvanced.ToString());

the output was 3 message boxes
true
false
false

which is the expected output
so i close the app down open the config and it's still true


so what have i missed
ShowAdvanced is scoped as user

5 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    the config if that helps is
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
                <section name="CDStarter.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            </sectionGroup>
        </configSections>
        <userSettings>
            <CDStarter.Properties.Settings>
                <setting name="ShowAdvanced" serializeAs="String">
                    <value>True</value>
                </setting>
            </CDStarter.Properties.Settings>
        </userSettings>
    </configuration>
    0
  • 0
    When you use a Settings file, you save the settings in what is known as "persistant storage". The settings will not save to the actual app.config in your solution, but they will save to a location selected by Windows under the Application Data folder in your Local Settings. The path goes something like this:

    C:\Documents and Settings\YOURUSERNAME\Local Settings\Application Data\NAMEOFAPPLICATION

    Look in there and see if you can see a "user.config" file. If you see it, that is where the settings are being stored for the application.

    Persistant storage is a nice feature for a few good reasons:

    Its out of the way of most user interaction.
    The application always knows where its at.
    The settings are somewhat permanent. Meaning that if you uninstall and reinstall the application, the settings will still be there and you wont need to reconfigure.

    Hope this helps =)
    0
  • 0
    okay that seems reasonable but when i restart the application the value is true even though i've saved it as false, which is why i was checking the config in the firstplace
    0
  • 0
    okay checks the local setting and it's false in there but when i load it it's still reading truei don't suppose the config with the exe is being used in preference to the local setting one is it. if so that explains the odd behaviour
    0
  • 0
    okay it's fixed, thanks for the help. i was looking at the wrong end for the problem the designer generated code was setting it to the properting during creattion and then overwriting it with true. so the config had no effect what so ever
    0