Adding a Custom Configuration file in C# application

笑着哭i 提交于 2019-12-08 03:10:01

问题


Is it possible to create a custom configuration file (other than app.config) that can be processed by classes in the System.Configuration namespace?

I have seen a ton of articles that talk about custom sections (inside the app.config file) but I would like to make an entirely new config file.

Is there any decent documentation that covers this topic?

thanks


回答1:


You do not state what you want to achieve by having a separate file, but there are a couple of different things you can do.

If you want to "modularize" you configuration, you can break out certain config sections to separate files, using the configSource attribute:

// point out a file containing the connectionStrings config section
<connectionStrings configSource="connections.config"></connectionStrings>

You can also open a specific configuration file by calling ConfigurationManager.OpenExeConfiguration.



来源:https://stackoverflow.com/questions/1061999/adding-a-custom-configuration-file-in-c-sharp-application

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