/// <summary>
/// 设置Conffig
/// </summary>
/// <param name="AppKey">Key值</param>
/// <param name="AppValue">Value值</param>
public static void SetValue(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");
xDoc.Save(AppConfig());
}
public static string AppConfig()
{
int intPos = Application.StartupPath.Trim().IndexOf("bin") - 1;
string strDirectoryPath = "";
try
{
//开发中调试时使用
}
catch (Exception)
{
//程序发布后因无 bin文件 修改
}
return strDirectoryPath;
}