C# 如何获取配置文件里的节点信息

来源:互联网 发布:淘宝头条 写作 编辑:程序博客网 时间:2024/04/30 15:05

项目过程中,有时候一些配置信息需要通过配置文件获取,比如web.config之类的文件。

方法如下:

string configPath = "D:/MyProject/trunk/IntOA.Operate.Service/Web.config";ExeConfigurationFileMap map = new ExeConfigurationFileMap();map.ExeConfigFilename = configPath;Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);AppSettingsSection appSection = (AppSettingsSection)config.GetSection("appSettings");KeyValueConfigurationElement tmp = appSection.Settings["CorpToken"];
那么就取到了节点<appSettings>下的<CorpToken>的信息。

0 0