WPF: changing custom configuration file settings at runtime?

I am trying to change some user settings for a configuration file in my WPF application, but it only works partially. The value changes correctly, and the program works fine with the value. I can even restart the program, and the value is still the one to which I changed it. The problem is that when I open the .exe.config file, the value is still old. I use this code to change the value:

Properties.Settings.Default.ProjectNumber = varTestExample;
Properties.Settings.Default.Save();

Where does this save code save the changes and how / where does the program read the value after running this code? If I run a clean version of the program, the ProjectNumber value will be correctly taken from the .exe.config file, and if I change the value in the configuration file, this will also change when the program starts. But as soon as I run the above code, the program does not read the value from the configuration file. Why?

+3
source share
3 answers

Settings are saved for each user. You should look in the folder Application Datain C:\Documents and Settings\[UserName]\...(WinXP) or in C:\Users\...(Vista / 7).

- , *.exe.config. , , . , .

+8

Properties.Settings , - , , ClickOnce Installs - , .

 private void updateDataInConfigFile()
    {
        Xml xmlConfigFile = new Xml(ProjectName.sSettingFileName);
        xmlConfigFile.SetValue("My Setting Section", "MyFirstSetting", MySettingValue);
}
  private void GetDataFromConfigFile()
    {
        Xml xmlConfigFile = new Xml(MyProject.sSettingFileName);

        txtAccessDriverId.Text = xmlConfigFile.GetValue("Mys Setting Section", "MyFirstSetting").ToString();
}
+2

User AppData. C:\Users\\AppData\Local\\

The values ​​stored in the .exe.config file are the default values ​​(which you set in the parameter editor in VS)

Hope this helps

0
source

Source: https://habr.com/ru/post/1737113/


All Articles