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
223 views
in Technique[技术] by (71.8m points)

c# - Save application preferences... registry/file?

Where is the best place to store application preferences?

In particular, I'd like to save preferences for a media player such as volume levels and the like. Two candidates spring to mind... file and registry. Which would be more appropriate?

As a follow up to this, I'm also wondering if there are any APIs that aid in creating application specific settings.

Unless someone advises me that this is wrong, I'd like to save stuff either in HKCU... or HKLM/Software/MyCompanyName/MyAppName/Key for the registry, or in %APPDATAMyCompanyNameMyAppNamesomeTypeOfSettingsFile.

As these seem to be commonly used for such settings, I'd assume that .Net makes it easy to store settings in these locations. Is there a simple high level API that can .Net offer me to read and write settings to these common locations?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Open settings.settings in your Visual Studio solution; add an application setting (i.e. change scope from 'user' to 'application').

The IDE creates a backing class that you can use in code.

The registry should be avoided.

The location of the app.exe.config and user.config files will differ based on how the application is installed. For a Windows Forms-based application copied onto the local computer, app.exe.config will reside in the same directory as the base directory of the application's main executable file, and user.config will reside in the location specified by the Application.LocalUserAppDataPath property. For an application installed by means of ClickOnce, both of these files will reside in the ClickOnce Data Directory underneath %InstallRoot%Documents and SettingsusernameLocal Settings.


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

...