Solved

How to: Load a RichTextBox control using stream (non-filestream)

Posted on 2004-08-17
3
622 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:bilpar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:bilpar
ID: 11827036
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.
0
 

Author Comment

by:bilpar
ID: 11827066
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
0
 
LVL 3

Accepted Solution

by:
Scoobyed earned 500 total points
ID: 11838642
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio hangs on running project 6 81
VB.NET - Refactor Class per SOLID principles 2 39
vb.net datagrid point 4 31
Check only one toolstripmenu item 12 56
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question