i m trying to create ebook editor in vb.net i design interface in VB.Net and use richtext box for editing, now the problem is how to store the contents from richtext box to xml file.
Main problem is where to put the xml code
behind the richtextbox
or
Create a new xml file
and how to start the xml code.
Yours trully,
Fahad Khan
AlanPosted Nov 23, 2007, 12:17 PM
Well, assuming it's well formed XML, you could save the text contents of the RTB to an XmlDocument and, if you wish, save it from there to a file on disk. Here's some basic code for that:
Dim doc As New XmlDocument();
Try
doc.LoadXml(richTextBox1.Text)
doc.PreserveWhitespace = True
doc.Save("c:\myfiles\myfile.xml") 'or whatever
Catch
MessageBox.Show("Invalid Xml")
End Try
Notice that the Save() method will overwrite any existing file with the same name.
I'm not sure what you mean by 'start the Xml' but you could reload it into an XmlDocument using:
doc.Load("c:\myfiles\myfile.xml") 'or whatever
If you have .NET 2.0 or later, you can also use the RTB's SaveFile() method to save the XML directly to a file as plain text:
richTextBox1.SaveFile("somefile.xml"
, RichTextBoxStreamType.PlainText)Again this overwrites any existing file of the same name. It can be reloaded into the RTB for further editing using the LoadFile() method:
richTextBox1.LoadFile("somefile.xml", RichTextBoxStreamType.PlainText)