Easiest way to read a config file belonging to another application

◇◆丶佛笑我妖孽 提交于 2019-12-01 03:58:32

问题


Other than using raw XML, is there an easy way in .NET to open and read a config file belonging to another assembly...? I don't need to write to it, just grab a couple of values from it.


回答1:


Here's MSDN on OpenExeConfiguration.

Edit: link to a how-to on eggheadcafe.com disappeared. Looks like EggheadCafe moved to NullSkull but dropped the article ID's.




回答2:


Have you tried ConfigurationManager and OpenExeConfiguration(path)? (in System.Configuration.dll)




回答3:


Or perhaps you could Serialize a simple class with the [Serializable()] attribute to a file... and deserialize in the other app...

http://www.dotnetperls.com/serialize-list
http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx

The sample program shows one short bit of code to serialize to a file and another to read file...

You can serialize to a file, to XML, to SOAP...



来源:https://stackoverflow.com/questions/239687/easiest-way-to-read-a-config-file-belonging-to-another-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!