问题:
What I want to achieve is very simple: I have a Windows Forms (.NET 3.5) application that uses a path for reading information. 我想要实现的非常简单:我有一个Windows Forms(.NET 3.5)应用程序,该应用程序使用读取信息的路径。 This path can be modified by the user, by using the options form I provide. 用户可以使用我提供的选项表单来修改此路径。
Now, I want to save the path value to a file for later use. 现在,我想将路径值保存到文件中以备后用。 This would be one of the many settings saved to this file. 这将是保存到该文件的众多设置之一。 This file would sit directly in the application folder. 该文件将直接位于应用程序文件夹中。
I understand three options are available: 我了解三个选项可供选择:
- ConfigurationSettings file (appname.exe.config) ConfigurationSettings文件(appname.exe.config)
- Registry 登记处
- Custom XML file 自定义XML文件
I read that the .NET configuration file is not foreseen for saving values back to it. 我读到没有预见到.NET配置文件来将值保存回它。 As for the registry, I would like to get as far away from it as possible. 至于注册表,我想尽可能地远离它。
Does this mean that I should use a custom XML file to save configuration settings? 这是否意味着我应该使用自定义XML文件保存配置设置? If so, I would like to see code example of that (C#). 如果是这样,我想查看该代码示例(C#)。
I have seen other discussions on this subject, but it is still not clear to me. 我已经看到了有关该主题的其他讨论,但是对我来说仍然不清楚。
解决方案:
参考一: https://stackoom.com/question/1tt3/如何在Windows窗体应用程序中保存应用程序设置参考二: https://oldbug.net/q/1tt3/How-to-save-application-settings-in-a-Windows-Forms-Application
来源:oschina
链接:https://my.oschina.net/stackoom/blog/4420901