如何使用读/写本地XML设置?
我在这里找到了与我需要的类似的东西: http://www.codeproject.com/KB/cs/PropertiesSettings.aspx 但它并不完全适合我。用户设置存储在一些较远的位置,例如 C:\documents and settings\[用户名]\local settings\application data\[your application],但我无权访问这些文件夹我无法将设置文件从一台计算机复制到另一台计算机,也无法完全删除该文件。此外,将设置 xml 文件放在应用程序旁边并复制/发送这两个文件会非常方便。这用于演示软件(这是一种合法的编码任务类型),并将由该领域的非技术人员使用。我需要快速完成此任务,因此我需要重用一些现有的库,而不是编写自己的库。我需要让它易于使用且便于携带。我最不想看到的就是在午夜接到电话,说通过我将构建的设置对话框进行编辑时,设置不会保留。
因此,用户设置存储在天知道在哪里,而应用程序设置是只读的(无法访问)。我还有什么可以做的吗?我认为 app.config 文件有多种用途,我想我曾经看到它按照我想要的方式使用,但我只是找不到链接。
如果有不清楚的地方请告诉我。
I found something similar to what I need here:
http://www.codeproject.com/KB/cs/PropertiesSettings.aspx
But it does not quite do it for me. The user settings are stored in some far away location such as C:\documents and settings\[username]\local settings\application data\[your application]
, but I do not have access to these folders and I cannot copy the settings file from one computer to another, or to delete the file altogether. Also, it would be super-convenient to have the settings xml file right next to the app, and to copy/ship both. This is used for demo-ware (which is a legitimate type of coding task) and will be used by non-technical people in the field. I need to make this quickly, so I need to reuse some existing library and not write my own. I need to make it easy to use and be portable. The last thing I want is to get a call at midnight that says that settings do not persist when edited through the settings dialog that I will have built.
So, user settings are stored god knows where, and application settings are read-only (no go). Is there anything else that I can do? I think app.config file has multiple purposes and I think I once saw it being used the way I want, I just cannot find the link.
Let me know if something is not clear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个类来保存您的设置,然后对其进行 XML 序列化:
You could create a class that holds your settings and then XML-serialize it: