FileHelper.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml;
  8. namespace OTSModelSharp.ServiceCenter
  9. {
  10. public static class FileHelper
  11. {
  12. public static string GetFolderName(string a_strPathName)
  13. {
  14. if (a_strPathName == "Untitled")
  15. {
  16. return null;
  17. }
  18. string folderName = a_strPathName.Substring(0, a_strPathName.LastIndexOf("\\"));
  19. return folderName;
  20. }
  21. /// <summary>
  22. /// 获取XML节点参数
  23. /// </summary>
  24. /// <param name="Name">节点参数名称</param>
  25. /// <returns>节点参数</returns>
  26. public static string GetXMLInformations(string Name)
  27. {
  28. try
  29. {
  30. string xmlFilePath = System.Configuration.ConfigurationManager.ConnectionStrings["XMLFileName"].ConnectionString;
  31. string value = string.Empty;
  32. XmlDocument doc = new XmlDocument();
  33. doc.Load(xmlFilePath); //加载Xml文件
  34. XmlElement root = doc.DocumentElement; //获取根节点
  35. XmlNodeList mainNodes = root.GetElementsByTagName("Member"); //获取子节点集合
  36. foreach (XmlNode node in mainNodes)
  37. {
  38. //获取Name属性值
  39. string name = ((XmlElement)node).GetAttribute("RegName");
  40. if (name.Equals(Name))
  41. {
  42. value = ((XmlElement)node).GetAttribute("Value");
  43. break;
  44. }
  45. }
  46. return value;
  47. }
  48. catch (Exception)
  49. {
  50. return "";
  51. }
  52. }
  53. }
  54. }