public void XmlConfigSet(string id, string val)
{
string file = Settings.Default.cfgpath;
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(file);
XmlElement newpath = xmldoc.CreateElement("Config");
XmlAttribute name = xmldoc.CreateAttribute("ID");
name.Value = id;
newpath.SetAttributeNode(name);
newpath.InnerText = val;
XmlNodeList xmlnode = xmldoc.SelectNodes("//*[@ID=" + ParseXpathString(id) + "]");
if (xmlnode != null)
{
if (xmldoc.DocumentElement != null)
{
if (xmlnode.Count > 0) {
xmldoc.DocumentElement.ReplaceChild(newpath, xmlnode[0]);
}
else
{
xmldoc.DocumentElement.InsertBefore(newpath, xmldoc.DocumentElement.FirstChild);
}
}
}
try
{
xmldoc.Save(file);
}
catch (UnauthorizedAccessException)
{
Error("Could not write to configuration file :'(\rModifications will not be saved\rPlease check your user permissions.");
}
}