private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { string folderPath = string.Empty; SaveFileDialog savefiledialog1 = new SaveFileDialog(); savefiledialog1.Filter = "Xml files (*.xml)|*.xml|All files (*.*)|*.*"; savefiledialog1.RestoreDirectory = true; if (savefiledialog1.ShowDialog() == DialogResult.OK) { folderPath = savefiledialog1.FileName; if (!System.IO.File.Exists(folderPath)) { XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); XmlComment comment = doc.CreateComment("This is an XML Generated File"); XmlElement root = doc.CreateElement("calcs"); XmlElement calc = doc.CreateElement("calc"); XmlAttribute Name = doc.CreateAttribute("Name"); //Add the values for each nodes Name.Value = textBox5.Text; //Construct the document doc.AppendChild(declaration); doc.AppendChild(comment); doc.AppendChild(root); root.AppendChild(calc); calc.Attributes.Append(Name); doc.Save(savefiledialog1.FileName); } //Show confirmation message MessageBox.Show("Details have been added to the XML File."); //Reset text fields for new input //textBox5.Text = String.Empty; } } private void openSignalChainToolStripMenuItem_Click(object sender, EventArgs e) { XmlDataDocument xmldoc = new XmlDataDocument(); OpenFileDialog openfiledialog1 = new OpenFileDialog(); // openfiledialog1.InitialDirectory = "c:\\"; openfiledialog1.FileName = "Document"; openfiledialog1.DefaultExt = ".xml"; openfiledialog1.Filter = "xml file (.xml)|*.xml"; openfiledialog1.FilterIndex = 2; Nullable<bool> result = Convert.ToBoolean(openfiledialog1.ShowDialog()); openfiledialog1.RestoreDirectory = true; if (result==true) { string filename = openfiledialog1.FileName; try { XmlNodeList xmlnode; int i = 0; string str = null; FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); xmldoc.Load(fs); xmlnode = xmldoc.GetElementsByTagName("Product"); for (i = 0; i <= xmlnode.Count - 1; i++) { xmlnode[i].ChildNodes.Item(0).InnerText.Trim(); str = xmlnode[i].ChildNodes.Item(0).InnerText.Trim() + " | " + xmlnode[i].ChildNodes.Item(1).InnerText.Trim() + " | " + xmlnode[i].ChildNodes.Item(2).InnerText.Trim(); MessageBox.Show(str); textBox5.Text = str; } } catch (Exception ex) { MessageBox.Show("File can not found!!!!"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)