Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
863 views
in Technique[技术] by (71.8m points)

vb.net - Where are application settings saved?

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 entering settings name, Type, Scope and Value

When I run the code, I read settings like this:

lastRunTime = My.Settings.LastRunTime

and set it like this:

My.Settings.LastRunTime = lastRunTime

Where can I actually see the new setting? Because for the love of God, I cannot see where it is updating the setting. app.config has the original setting value when I created that setting. So where can I see it?

When I run the code, I see it updates it and the next time I run the app the new value persists, so I know it stores it somewhere. But where?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.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:UsersusernameAppDataLocalWindowsFormsApplication1WindowsFormsApplication1._Url_twchbbo4atpsvjpauzkgkvesu5bh2aul1.0.0.0user.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...