从指定的文件读取配置项
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了从指定的文件读取配置项相关的知识,希望对你有一定的参考价值。
/// <summary> /// 从指定的文件读取配置项 /// </summary> /// <param name="fileName">配置文件</param> public static void GetConfig(string fileName,string key) { XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(fileName); string returnValue = string.Empty; XmlNodeList xmlNodeList = xmlDocument.SelectNodes("//appSettings/add"); foreach (XmlNode xmlNode in xmlNodeList) { if (xmlNode.Attributes["key"].Value.ToUpper().Equals(key.ToUpper())) { returnValue = xmlNode.Attributes["value"].Value; break; } } }
<?xml version="1.0" encoding="utf-8" ?>
<configuration> <configSections> <sectionGroup name="userSettings_HJDSTM" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <section name="HJ.DSTM.MainForms.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" /> </sectionGroup> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> </configSections> <appSettings> <!-- DotNet.Business DotNet.Service DotNet.WCFClient xxf 2013-11-14--> <add key="Service" value="DotNet.Business" />
以上是关于从指定的文件读取配置项的主要内容,如果未能解决你的问题,请参考以下文章