bilpar
asked on
How to: Load a RichTextBox control using stream (non-filestream)
Hello,
I have a RichTextBox control on a VB .NET form. I have successfully translated an XML document into RTF and would like to load it into the RichTextBox control without writing the results of the XSLT translation to a file... Thanks in advance for your help. Here's what I have so far:
Private Sub LoadRichTextBox()
'vars
Dim _XmlDoc As New XmlDocument()
Dim _XslDoc As New System.Xml.Xsl.XslTransfor m()
Dim _XmlTextWriter As XmlTextWriter
'**Dim _MemoryStream As New MemoryStream()
_XmlDoc.Load("Source.xml")
_XslDoc.Load("xml2rtf.xslt ")
'transform to RTF and save it to file.
_XmlTextWriter = New XmlTextWriter("Temp.rtf", System.Text.Encoding.Defau lt)
_XslDoc.Transform(_XmlDoc, Nothing, _XmlTextWriter)
'** _XslDoc.Transform(_XmlDoc, Nothing, _MemoryStream)
'** i would like to use a stream rather than a file here!
txtDsr.LoadFile("Temp.rtf" , RichTextBoxStreamType.Rich Text)
'** txtDsr.LoadFile(_MemoryStr eam, RichTextBoxStreamType.Rich Text)
_XmlTextWriter.Close()
'** _MemoryStream.Close()
End Sub
I have a RichTextBox control on a VB .NET form. I have successfully translated an XML document into RTF and would like to load it into the RichTextBox control without writing the results of the XSLT translation to a file... Thanks in advance for your help. Here's what I have so far:
Private Sub LoadRichTextBox()
'vars
Dim _XmlDoc As New XmlDocument()
Dim _XslDoc As New System.Xml.Xsl.XslTransfor
Dim _XmlTextWriter As XmlTextWriter
'**Dim _MemoryStream As New MemoryStream()
_XmlDoc.Load("Source.xml")
_XslDoc.Load("xml2rtf.xslt
'transform to RTF and save it to file.
_XmlTextWriter = New XmlTextWriter("Temp.rtf", System.Text.Encoding.Defau
_XslDoc.Transform(_XmlDoc,
'** _XslDoc.Transform(_XmlDoc,
'** i would like to use a stream rather than a file here!
txtDsr.LoadFile("Temp.rtf"
'** txtDsr.LoadFile(_MemoryStr
_XmlTextWriter.Close()
'** _MemoryStream.Close()
End Sub
ASKER
Hello again,
I did manage to get this working. So I would like to change the question. I have coded several functions using streams but i do not fully understand how these darn things work. So, each time I hunt and guess... until something good happens. I think it best that I fully understand how they work.
The question is now: "Please point me to a good tutorial on working with Streams"
Thanks,
Bil
I did manage to get this working. So I would like to change the question. I have coded several functions using streams but i do not fully understand how these darn things work. So, each time I hunt and guess... until something good happens. I think it best that I fully understand how they work.
The question is now: "Please point me to a good tutorial on working with Streams"
Thanks,
Bil
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have made some progress... Uncommenting the _MemoryStream lines of code and adding the following line just before the txtDsr.LoadFile:
_MemoryStream.Seek(0, SeekOrigin.Begin)
yields:
"Invalid file format"
By the way, I meant to rename txtDsr to RichTextBox1 in the example above.