Where are application settings saved?

后端 未结 4 1556
悲哀的现实
悲哀的现实 2020-12-06 23:51

I am trying to store some persistent application data so I\'ve added a setting to the project by R-Clicking on it, selecting properties, then Settings tab and manually enter

4条回答
  •  北海茫月
    2020-12-07 00:03

    .NET has to do something special, it has to give you a guarantee that another program that also happens to have a "LastRuntime" setting doesn't overwrite the value that's stored for your program. To do that, it stores a user.config file in a directory that's hard to find back. It has a weirdo name, like

    C:\Users\username\AppData\Local\WindowsFormsApplication1\WindowsFormsApplication1._Url_twchbbo4atpsvjpauzkgkvesu5bh2aul\1.0.0.0\user.config

    Note how the project name is part of the path, that's one way to find it back. The unspeakable part of the name is a hash, created from various properties of your project that make your app unique enough to not collide with another .NET program, even if the name matches. Like your product name, company name, exe name, etcetera.

    Note how the converse is true as well, changing such a property makes you lose your user.config file. So if "LastRuntime" is some kind of license metering value then using a setting isn't the best idea.

提交回复
热议问题