Link to home
Start Free TrialLog in
Avatar of bilpar
bilparFlag for United States of America

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.XslTransform()
      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.Default)
       _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.RichText)
       '** txtDsr.LoadFile(_MemoryStream, RichTextBoxStreamType.RichText)

        _XmlTextWriter.Close()
        '** _MemoryStream.Close()

   End Sub
Avatar of bilpar
bilpar
Flag of United States of America image

ASKER

Hello,

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.
Avatar of bilpar

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
ASKER CERTIFIED SOLUTION
Avatar of Scoobyed
Scoobyed

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial