Problem with code after ShowDialog and XML add node
-
Hello, The code below I have:- static string filename; static XmlDocument xmlDoc; and open the XML file in the Form Load. If I remove the :- if (testDialog.ShowDialog() == DialogResult.OK) Line the XML addnode code works OK. With the ShowDialog() line in the XML node add code does not work. Why? Also is there something I can check (return code?) to make sure each part of the add node lines of code has worked? void Button1Click(object sender, EventArgs e) { NewForm testDialog = new NewForm(); if (testDialog.ShowDialog() == DialogResult.OK) { MessageBox.Show("Here"); XmlNode root = xmlDoc.DocumentElement; XmlElement childNode = xmlDoc.CreateElement("ABCD"); XmlElement childNode2 =xmlDoc.CreateElement("Name"); XmlText textNode = xmlDoc.CreateTextNode("ABCD"); root.AppendChild(childNode); childNode.AppendChild(childNode2); childNode2.SetAttribute("Name", "Name"); childNode2.AppendChild(textNode); xmlDoc.Save(filename); MessageBox.Show("Here2"); } testDialog.Dispose(); } Thanks is Advance, Rapier
-
Hello, The code below I have:- static string filename; static XmlDocument xmlDoc; and open the XML file in the Form Load. If I remove the :- if (testDialog.ShowDialog() == DialogResult.OK) Line the XML addnode code works OK. With the ShowDialog() line in the XML node add code does not work. Why? Also is there something I can check (return code?) to make sure each part of the add node lines of code has worked? void Button1Click(object sender, EventArgs e) { NewForm testDialog = new NewForm(); if (testDialog.ShowDialog() == DialogResult.OK) { MessageBox.Show("Here"); XmlNode root = xmlDoc.DocumentElement; XmlElement childNode = xmlDoc.CreateElement("ABCD"); XmlElement childNode2 =xmlDoc.CreateElement("Name"); XmlText textNode = xmlDoc.CreateTextNode("ABCD"); root.AppendChild(childNode); childNode.AppendChild(childNode2); childNode2.SetAttribute("Name", "Name"); childNode2.AppendChild(textNode); xmlDoc.Save(filename); MessageBox.Show("Here2"); } testDialog.Dispose(); } Thanks is Advance, Rapier
Does your NewForm return a DialogResult anywhere in your code? Supposing that the NewForm form has been created by you.
There are 10 kinds of people: those who understand binary and those who don't