如何将应用程序设置保存到文件?

发布于 2024-10-12 00:15:11 字数 220 浏览 7 评论 0原文

我有简单的应用程序。更具体地说,这是 Visual Studio Addin。 客户端需要指定几个设置(字符串、整数、十进制等),

我需要能够在启动时加载它并在更改时保存。

为简单起见,我将所有设置都放在一类 AppSettings 中。

我当然可以使用 DataContractSerializer 来序列化/反序列化 AppSettings 但 我认为必须有一些标准的方法。

I have simple application. To be more specific this is Visual Studio Addin.
Client needs to specify several settings (string, int, decimal etc)

I need to be able to load it at starup time and save if changed.

Let's say for simplicity I have all settings in one class AppSettings.

I can of course use DataContractSerializer to serialize/deserialize AppSettings but
I think there must be some standard way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

大姐,你呐 2024-10-19 00:15:11

有来自 Microsoft 的应用程序设置:

http://msdn.microsoft.com/en-us/library/a65txexh.a​​spx ?appId=Dev10IDEF1&l=EN-US&k=k(APPLICATIONSETTINGSOVERVIEW);k(TargetFrameworkMoniker-%22.NETFRAMEWORK&k=VERSION=V4.0%22)&rd=true

你可以使用它像这样:

Properties.Settings.Default.DumpHeader = dumpHeader;
Properties.Settings.Default.DumpFooter = dumpFooter;

Properties.Settings.Default.Save();

加载工作类似。但您必须首先定义一个 .settings 文件。它来自 WPF 框架,不确定它是否也适用于 WinForms。

类似的问题有类似的答案:
在 Windows 窗体应用程序中保存应用程序设置的最佳实践< /a>

There are Application Settings from Microsoft:

http://msdn.microsoft.com/en-us/library/a65txexh.aspx?appId=Dev10IDEF1&l=EN-US&k=k(APPLICATIONSETTINGSOVERVIEW);k(TargetFrameworkMoniker-%22.NETFRAMEWORK&k=VERSION=V4.0%22)&rd=true

You can use it like this:

Properties.Settings.Default.DumpHeader = dumpHeader;
Properties.Settings.Default.DumpFooter = dumpFooter;

Properties.Settings.Default.Save();

And loading works similar. But you have to define a .settings file first. It's from the WPF Framework, not sure if it works for WinForms too.

Similar question with a similar answer:
Best practice to save application settings in a Windows Forms Application

留蓝 2024-10-19 00:15:11

我本人非常喜欢平面文件存储,例如 INI 文件。可以在此处<找到一篇文章,其中包含有关如何在 .NET 中使用 INI 文件的示例代码/a>.

I'm a huge fan of flat file storage myself, for example INI files. An article with example code on how to use INI files with .NET can be found here.

时光瘦了 2024-10-19 00:15:11

Visual Studio Addin 是一个特例。在这种情况下,如果您想使用标准安装插件包。当我遇到这样的问题时,我尝试使用 Windows 注册表来解决它。您可以找到很多如何在 C# 中处理 Windows 注册表的示例。

Visual Studio Addin is specific case. In this case we can distribute only a .dll file which contain add in code and some .xml with Add-in definition if you want to use standard installation Add-In package. When I had such problem I try to resolve it with Windows registry. You can find a lot of examples how to deal with Windows registry in c#.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文