Winform读写App.config文件以及重启程序
2016-08-07 05:28
447 查看
//重启主程序
//System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
#region 读存app.config字段值
public static string GetConfigValue(string appKey)
{
XmlDocument xDoc = new XmlDocument();
try
{
//缓存路径
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
System.Xml.XmlNode xNode;
System.Xml.XmlElement xElem;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
if (xElem != null)
return xElem.GetAttribute("value");
else
return "";
}
catch
{
return "";
}
}
public static void SetConfigValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null) xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
#endregion
//System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location);
#region 读存app.config字段值
public static string GetConfigValue(string appKey)
{
XmlDocument xDoc = new XmlDocument();
try
{
//缓存路径
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
System.Xml.XmlNode xNode;
System.Xml.XmlElement xElem;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
if (xElem != null)
return xElem.GetAttribute("value");
else
return "";
}
catch
{
return "";
}
}
public static void SetConfigValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config");
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if (xElem1 != null) xElem1.SetAttribute("value", AppValue);
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config");
}
#endregion
//重启主程序 //System.Diagnostics.Process.Start(System.Reflection.Assembly.GetExecutingAssembly().Location); #region 读存app.config字段值 public static string GetConfigValue(string appKey) { XmlDocument xDoc = new XmlDocument(); try { //缓存路径 xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config"); System.Xml.XmlNode xNode; System.Xml.XmlElement xElem; xNode = xDoc.SelectSingleNode("//appSettings"); xElem = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']"); if (xElem != null) return xElem.GetAttribute("value"); else return ""; } catch { return ""; } } public static void SetConfigValue(string AppKey, string AppValue) { XmlDocument xDoc = new XmlDocument(); xDoc.Load(System.Windows.Forms.Application.ExecutablePath + ".config"); XmlNode xNode; XmlElement xElem1; XmlElement xElem2; xNode = xDoc.SelectSingleNode("//appSettings"); xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']"); if (xElem1 != null) xElem1.SetAttribute("value", AppValue); else { xElem2 = xDoc.CreateElement("add"); xElem2.SetAttribute("key", AppKey); xElem2.SetAttribute("value", AppValue); xNode.AppendChild(xElem2); } xDoc.Save(System.Windows.Forms.Application.ExecutablePath + ".config"); } #endregion
相关文章推荐
- Winform读写App.config文件以及重启程序
- Winform读写App.config文件以及重启程序
- Winform读写App.config文件以及重启程序
- winform客户端程序实时读写app.config文件
- C# WinForm程序的App.Config数据库连接配置文件
- c#,WinForm中读写配置文件App.config
- winform程序读取和改写配置文件App.config元素的值
- c# winform app.config xml 配置文件 读写操作
- C# WinForm程序App.Config数据库连接配置文件的使用过程
- winform程序读取和改写配置文件App.config元素的值
- winform程序读取和改写配置文件App.config元素的值
- winform程序读取和改写配置文件App.config元素的值
- winform 程序的配置文件——App.config(转)
- C# WinForm程序的App.Config数据库连接配置文件
- [原创]读写app.config以及web.config文件中的appSettings节次内容
- winform程序读取和改写配置文件App.config元素的值
- c#,WinForm中读写配置文件App.config
- c#,WinForm中读写配置文件App.config
- 【转】C# WINFORM 应用程序动态读写xml config文件,获取数据库连接并对App.config文件进行加密
- winform程序读取和改写配置文件App.config元素的值