Windows窗体中web.config文件的替代方案 [英] Alternative for web.config file in windows form

查看:91
本文介绍了Windows窗体中web.config文件的替代方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Windows窗体应用程序中添加web.config文件。什么是web.config文件的替代品。

I am not able to add web.config file in my windows form application. Whats the alternative to web.config file.

推荐答案

这取决于你需要什么。如果您只需要在某些特殊情况下手动编辑用户手动编辑的只读配置数据(例如,最初调整应用程序),app.config就可以了。此名称app.config仅是源文件和项目节点的名称;在构建时,它在输出目录中创建为文件yourApplication.exe.config。配置文件由应用程序读取并仅用于初始化,它可以带有自定义和许多标准选项。请参阅:

http:// msdn .microsoft.com / zh-CN / library / ms229689%28v = vs.90%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ee523958.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/1fk1t1t0%28v=vs.110%29.aspx [ ^ ]。



如果您需要您的应用程序具有读/写访问权限,以便持久保存应用程序状态并保存/恢复某些选项,可以使用应用程序设置。请从这里开始:

http:// msdn.microsoft.com/en-us/library/k4s6c3a0%28v=vs.110%29.aspx [ ^ ]。



但是,我避免使用应用设置;对我来说,他们不够灵活,可能在道德上已经过时了。我更喜欢更通用和灵活的方法:基于数据合同的自定义文件。请参阅:

http:// msdn .microsoft.com / zh-CN / library / ms733127%28v = vs.110%29.aspx [ ^ ]。



在这种情况下你需要自己选择文件位置(它永远不应该硬编码),请看我过去的答案:

如何查找我的程序目录 [ ^ ],

哪个更好:使用registery来存储设置或使用Settings类 [ ^ ],

无法找到'installallusers'属性 [ ^ ]。



祝你好运,

-SA
It depends on what do you need. If you need read-only configuration data editable by the users manually only in some special cases (say, tune-up the application initially), "app.config" would be perfectly fine. This name, "app.config", is only the name of the source file and project node; on built, it is created in the output directory as the file "yourApplication.exe.config". Configuration files are read by the application and used only for the initialization of it, it could carry custom and a number of "standard" options. Please see:
http://msdn.microsoft.com/en-us/library/ms229689%28v=vs.90%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ee523958.aspx[^],
http://msdn.microsoft.com/en-us/library/1fk1t1t0%28v=vs.110%29.aspx[^].

If you need your application have read/write access for the purpose of persisting of the application state and saving/restoring some options, you can use application settings. Please start here:
http://msdn.microsoft.com/en-us/library/k4s6c3a0%28v=vs.110%29.aspx[^].

However, I avoid using application settings; to me, they are not flexible enough and probably morally outdated. I prefer more universal and flexible approach: custom files based on Data Contract. Please see:
http://msdn.microsoft.com/en-us/library/ms733127%28v=vs.110%29.aspx[^].

As in this case you need to choose the file location by yourself (it never ever should be hard-coded), please see my past answers:
How to find my programs directory[^],
which is better : use of registery in order to store setting or use of Settings class[^],
Cant find 'installallusers' property[^].

Good luck,
—SA


这篇关于Windows窗体中web.config文件的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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