什么是存储用户设置一个.NET应用程序的最佳方法是什么? [英] What is the best way to store user settings for a .NET application?

查看:118
本文介绍了什么是存储用户设置一个.NET应用程序的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET 2.0的Windows窗体应用程序。哪里是最好的地方保存用户设置(考虑到Windows的标准)?

I have a .NET 2.0 Windows Forms application. Where is the best place the store user settings (considering Windows guidelines)?

有人指出, Application.LocalUserAppDataPath 。然而,创建一个文件夹结构,如:

Some people pointed to Application.LocalUserAppDataPath. However, that creates a folder structure like:

C:\Documents and Settings\user_name\Local Settings\Application Data\company_name\product_name\product_version\

如果我释放我的应用程序的版本1和存储的XML文件在那里,然后释放第2版,将切换到不同的文件夹,对不对?我想preFER有一个单独的文件夹,每个用户,存储设置,无论应用程序版本。

If I release version 1 of my application and store an XML file there, then release version 2, that would change to a different folder, right? I'd prefer to have a single folder, per user, to store settings, regardless of the application version.

推荐答案

我喜欢使用内置的应用程序设置。然后,你已经建立了使用的设置设计师的支持,如果你想在设计时,或在运行时使用的:

I love using the built-in Application Settings. Then you have built in support for using the settings designer if you want at design-time, or at runtime to use:

// read setting
string setting1 = (string)Settings.Default["MySetting1"];
// save setting
Settings.Default["MySetting2"] = "My Setting Value";

// you can force a save with
Properties.Settings.Default.Save();

它确实存放在类似的文件夹结构的设置为你描述(在路径中的版本)。然而,一个简单的调用:

It does store the settings in a similar folder structure as you describe (with the version in the path). However, with a simple call to:

Properties.Settings.Default.Upgrade(); 

应用程序将拉都previous版本设置,保存在

The app will pull all previous versions settings in to save in.

这篇关于什么是存储用户设置一个.NET应用程序的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆