.Settings在Win表格应用程序文件,最佳实践 [英] .Settings file in Win Form App, Best Practice

查看:165
本文介绍了.Settings在Win表格应用程序文件,最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个双赢表格应用程序,存储了一些每个用户设置一个UserSettings.Settings文件。这一直运作良好,到目前为止,但它似乎设置文件获取重启当过我发布一个更新。我通过的ClickOnce 做的。

I have a Win Form app that stores some per user settings in a UserSettings.Settings file. This has worked well so far, however it seems that the Settings file gets "reset" when ever I release an update. Which I do through ClickOnce.

这是预期的行为?
我可以控制,如果在设置域文件被覆盖?
有没有更好的办法,我要保存用户设置?

Is this the expected behavior?
Can I control if fields in the Settings file get overwritten?
Is there a better way I should store user settings?

感谢

推荐答案

当你发布的更新更新后的应用程序应该调用<一个href="http://msdn.microsoft.com/en-us/library/system.configuration.applicationsettingsbase.upgrade.aspx"相对=nofollow> ApplicationSettingsBase.Upgrade方法从previous版本移到值。这是一个类似的问题:<一href="http://stackoverflow.com/questions/1198193/automatically-upgrade-user-settings-from-$p$pvious-version-of-app-config-file">Automatically从app.config文件的previous版本升级用户设置?

When you release an update your updated app should call ApplicationSettingsBase.Upgrade Method to move values from the previous version. Here is a similar question: Automatically "upgrade" user settings from previous version of app.config file?

请记住,你应该调用上述方法只有一次,所以你可能要保存您是否已经呼吁升级与否的设置也是一样,做这样的事情:

Keep in mind that you should call the above method only once so you probably will have to store whether you have already called Upgrade or not in the settings too and do something like this:

if(!Settings.Default.Upgraded)
{
   Settings.Default.Upgrade();
   Settings.Default.Upgraded = true;
   Settings.Default.Save();
}

另一种可能的解决方案是,以存储不依赖于应用程序的版本的文件夹中设置。在这种情况下,你不会失去价值观,就没有必要升级版本之间设置。

Another possible solution is to store settings in a folder that does not depend on the application version. In that case you will not lose values and there will be no need to upgrade settings between versions.

这篇关于.Settings在Win表格应用程序文件,最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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