- public Dictionary<string, string> GetCustomConfigText(string guid)
- {
- try
- {
- string path = Application.StartupPath;
- string filecustom = path + "\\Config\\custom.xml";
- string filetemplate = path + "\\Config\\template.xml";
- string FilePath = "";
- // 如果自定义配置文件不存在, 则读取模版配置文件
- if (File.Exists(filecustom))
- {
- FilePath = filecustom;
- }
- else
- {
- FilePath = filetemplate;
- }
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load(FilePath);// 读取指定的 xml 文档
- XmlNode devicelist = xmlDoc.SelectSingleNode("DeviceList");
- foreach (XmlNode device in devicelist.ChildNodes)
- {
- XmlNodeList list = device.ChildNodes;
- foreach (XmlNode item in list)
- {
- if (!string.IsNullOrEmpty(guid) && device.Attributes["Guid"] != null)
- {
- var deviceGuid = device.Attributes["Guid"].Value;
- if (deviceGuid == guid)
- {
- DicCustomText[item.Name] = item.InnerText;
- }
- }
- else
- {
- DicCustomText[item.Name] = item.InnerText;
- }
- }
- }
- }
- catch (Exception ex)
- {
- log4netHelp.Error(ex.Message);
- }
- return DicCustomText;
- }
来源: http://www.bubuko.com/infodetail-3066697.html