1

I have a windows app written in C# (.net 3.5), and have a Settings.settings file that holds the application's settings.

When I do something like this:

Properties.Settings.Default.HSLastSend = DateTime.Now;
Properties.Settings.Default.Save();

it gets saved and persisted when I restart the application, however the Settings.settings file still has the original value. I can't seem to find where this new value is stored. I would have expected the Settings.settings file to have the new value when I went into it.

Is this a problem or normal?

Cheers in advance,

Stu

stuartw87
  • 119
  • 2
  • 9

2 Answers2

1

Setting.settings provide default values for the application, instead changed one, is saved in your binary file resources. You can prove it by loading your application after save changed settings, and you will get you changed value, even if Settings file has still "old" one.

EDIT

Just note that Properties.Settings.Default.

On XP machine it should be at:

C:\Documents and Settings\"YourMachineUserName"\Application Data\

Regards.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • OK, so if I distribute the application as things currently stand, it would use the binary saved version as opposed to the default in Settings.settings? – stuartw87 Jul 21 '11 at 10:25
  • 1
    Another important thing is to consider the -scope- of the setting. It can either be user or application, which means it'll be persisted in different places. – J. Steen Jul 21 '11 at 10:27
  • @stuart I update my post. The asnwer on your comment is no, it saved on yuor PC. – Tigran Jul 21 '11 at 10:56
  • @stuart: there is another question, I think the same you ask on SO, just found: http://stackoverflow.com/questions/5789252/properties-settings-default-save-where-is-that-file, seemed strange to me that none asked before something like this :) – Tigran Jul 21 '11 at 10:58
  • Cheers for the answers guys. I think I got it now. The settings.settings file is the initial value, but when I do a save, it'll store it off elsewhere and read from there instead. However, does this mean that if I change the default values in the settings.settings file it won't make any difference? – stuartw87 Jul 21 '11 at 15:05
0

This is normal the settings file stores static values only and is designed for storing runtime application settings in a centralized place dynamic values such as DateTime.Now cannot be stored in this manner if you want the current DateTime why not call it in your code

Chris McGrath
  • 1,727
  • 3
  • 19
  • 45
  • -1, it is saving the last time the application did something not the current DateTime. That's my understanding of the code anyway. – Stuart Blackler Jul 21 '11 at 11:00
  • 1
    which is exactly what i was explaining you cant have the settings file store a persistantly updated value it will only keep the last value stored to it try reading the response a little closer next time before voting someone down – Chris McGrath Jul 21 '11 at 12:10