Saving form data to file or xml


Active member
Mar 26, 2005
Programming Experience
I am looking for a sample of saving form data to a file with a custom extension or xml file. Is there a built in method to save all data in a form and reload it later or do you have to write a routine to save all the data one by one to a file?
use XML

I think it's the best when you use XML for this. If you want to write it to your file, you just load it, create the right node, and add the text you want to.
And reading from the file is the same, load your xml-file, navigate to the right node, and ask the innerText porperty, that will give you the text of that node.
Does this help?
I need to save out data from text boxes on a simple form. Basically just to provide a way for users to save and load data during different sessions of using the app. I am a vb newbie, so any advice would be appreciated. I would like to save the data in xml format, but am curious of making data files with my own extension too.

Thanks in advance.
It would probably be easier to just write it to a text file with a streamwriter then. Unless you need it in XML form for some reason.

Oké, I think this discussion is getting a bit ridiculous and is not answering the guys question. If you want to write data, you can indeed chose for a text file or for an XML file. But if you have to read it, I think it will be much easier to read it from a XML file than from a text file. And it’s not that difficult to make it, you don’t need an xslt file, you can make the format right with VB.

An example will clear everything

So, you already made your xml file with the declaration and the root element. Then you just have to

Private Sub addToXML()

Dim moDoc as new xmlDocument


Dim oXmlPart As XmlElement

oXmlPart = moDoc.CreateElement("part")

'add attribute

oXmlPart.SetAttribute("nr", miChapterPart)

Dim oElement As XmlElement

oElement = moDoc.CreateElement("text")

oElement.InnerText() = txtChapterPart.Text


oElement = moDoc.CreateElement("sound")

oElement.InnerText() = txtSound.Text


Dim oXmlChapter As XmlElement

oXmlChapter = moDoc.SelectSingleNode("//chapter")



End Sub

And if you want to read you xml file is even easier

oPart = moDoc.SelectSingleNode("//chapter/part[@nr='" & sNummer & "']")

Dim sText As String

oElement = oPart.SelectSingleNode("text")

sText = oElement.InnerText

txtChapterPart.Text = sText

Dim sSound As String

oElement = oPart.SelectSingleNode("sound")

sSound = oElement.InnerText

txtSound.Text = sSound

Dim sMovie As String

oElement = oPart.SelectSingleNode("movie")

sMovie = oElement.InnerText

txtMovie.Text = sMovie

I hope this makes it a bit clear. And you can see that it's realy easy to use.