设置app.config中的某个key的value.
/// <summary>
/// 设置app.config中的某个key的value.
/// </summary>
/// <param name="AppKey">key</param>
/// <param name="AppValue">value</param>
public void SetValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
//此处配置文件在程序目录下
xDoc.Load(Application.StartupPath + "\\PoCollect.exe.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(Application.StartupPath + "\\PoCollect.exe.config");
}
/// 设置app.config中的某个key的value.
/// </summary>
/// <param name="AppKey">key</param>
/// <param name="AppValue">value</param>
public void SetValue(string AppKey, string AppValue)
{
XmlDocument xDoc = new XmlDocument();
//此处配置文件在程序目录下
xDoc.Load(Application.StartupPath + "\\PoCollect.exe.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(Application.StartupPath + "\\PoCollect.exe.config");
}
帅哥
2009/11/18 08:58
确实好用啊。谢了
Pages: 1/1
1
1
用C#调用Word.printout打印时如何指定打印机
薄熙来你有什么钱发短信?
