string xpath = xpathNode.InnerText; if (string.IsNullOrEmpty(xpath)) { log.Error("XPath value not found!"); return false; }
XmlNode nodeToInsertNewNodeInto = webconfig.SelectSingleNode(xpath); if (nodeToInsertNewNodeInto == null) { log.Error("nodeToInsertNewNodeInto node not found via xpath!"); return false; }
XmlNode xmlNode = xmlData.SelectSingleNode("XmlNode"); if (xpathNode == null) { log.Error("XmlNode node not found!"); return false; }
if (xmlNode.ChildNodes.Count == 0) { log.Error("No child node to XmlNode found!"); return false; }
if (xmlNode.ChildNodes.Count > 1) { log.Error("More than one child node found!"); return false; }
XmlNode insertAfterNodeXpath = xmlData.SelectSingleNode("InsertAfter"); if (insertAfterNodeXpath != null && !string.IsNullOrEmpty(insertAfterNodeXpath.InnerText)) { insertAfterNode = webconfig.SelectSingleNode(insertAfterNodeXpath.InnerText); if (insertAfterNode == null) { log.Error("insertAfterNode not found, but will insert the new node to XPath location!"); } }
That's awesome - good job! Great for not using WebConfigurationManager too, modifying the web.config only works through an XmlDocument in Medium Trust.
AddXmlNodeToWebConfig
I have created a AddXmlNodeToWebConfig - you can use it whenever you wan't to add something to the web.config.
You can provide a XPathCheckIfExist to ensure you do not create duplicates
Sample
Source (using log4net, undo not implemented)
That's awesome - good job! Great for not using WebConfigurationManager too, modifying the web.config only works through an XmlDocument in Medium Trust.
I'll bring this to Rich Soeteman's attention.
Best,
Benjamin :-)
Nice Christian,
Will add it for the nex release.
Thanks,
Richard
is working on a reply...