create xml file using streamwriter
-
Hi im trying to use this line of code to create an xml file but it just overwrites it every time or appends to the wrong part. I have tried changing the bool to true and false also tried changing write to writeline nothing works please help. using (StreamWriter sw = new StreamWriter("TestFile.xml")) { sw.Write("" + " " + DispID.Text + "" + " " + listBox2.SelectedItem.ToString() + "" + " " +listBox3.SelectedItem.ToString()+ "" + "" ); } Thanks alot, :-D:-D:-D Da Intern
-
Hi im trying to use this line of code to create an xml file but it just overwrites it every time or appends to the wrong part. I have tried changing the bool to true and false also tried changing write to writeline nothing works please help. using (StreamWriter sw = new StreamWriter("TestFile.xml")) { sw.Write("" + " " + DispID.Text + "" + " " + listBox2.SelectedItem.ToString() + "" + " " +listBox3.SelectedItem.ToString()+ "" + "" ); } Thanks alot, :-D:-D:-D Da Intern
-
Hi Isn´t XmlTextWriter a better choice? in VB Dim wrtXMLWriter As New XmlTextWriter("TestFile.xml", Nothing) and use .WriteRaw or any other XmlTextWriter-method that works for your purposes. Regards Daniel
okay but i want it to create a new set of elements like this: when i click this button it creates the xml file and the first element then when i click it again it adds the new elements to that xml file. Da Intern
-
okay but i want it to create a new set of elements like this: when i click this button it creates the xml file and the first element then when i click it again it adds the new elements to that xml file. Da Intern
You can use XmlDocument.CreateElement and .AppendChild to add your information to your document. in c++ given that Child,Name,TopElement all are XmlElements sData is the content, the info in the element; ChildElement = doc->CreateElement("tagname"); TopElement->AppendChild(ChildElement); NameElement = doc->CreateElement("tagname"); NameElement->InnerText = sData; ChildElement->AppendChild(NameElement); .. or something like that I guess you have to check in the button_click function if you already have pressed the button and if not -> create a new xmldokument Regards:) Daniel