Files
tj-tzhg/JJMediSys/cs/ConfigFileReader.cs

39 lines
1.3 KiB
C#
Raw Normal View History

2025-11-26 17:20:53 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace JJMediSys.cs
{
public class ConfigFileReader
{
static XmlDocument xmlDocument = null;
static string filepath = System.AppDomain.CurrentDomain.BaseDirectory + "\\JJMediSys.exe.config";
public static string GetValue(string key)
{
if (xmlDocument == null)
xmlDocument = new XmlDocument();
xmlDocument.Load(filepath);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
XmlNode xmlNode = xmlDocument.SelectSingleNode(key, nsmgr);
XmlElement Xe = (XmlElement)xmlNode;
return Xe.GetAttribute("value");
}
public static void SetValue(string appKey, string newValue)
{
if (xmlDocument == null)
xmlDocument = new XmlDocument();
xmlDocument.Load(filepath);
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDocument.NameTable);
XmlNode xmlNode = xmlDocument.SelectSingleNode(appKey, nsmgr);
XmlElement Xe = (XmlElement)xmlNode;
Xe.SetAttribute("value", newValue);
xmlDocument.Save(filepath);
}
}
}