Solved

Convert a string to memorystream to stream to client

Posted on 2004-08-11
5
1,474 Views
Last Modified: 2012-08-14
Hello.

I have a string containing some xml, what is the best way to throw that string into a memory stream?  I want to to do this so then I can stream that memory stream to the client browser -- I already know how to do that part.

Thanks.
0
Comment
Question by:fishrich
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 250 total points
Comment Utility
Try this:

        Dim strText As String = "This is some text"
        Dim objEncoding As Encoding = Encoding.Unicode
        Dim objMs As New System.IO.MemoryStream(objEncoding.GetBytes(strText))

You will need to import System.Text for the Encoding class to show up in intellisense.
0
 
LVL 2

Author Comment

by:fishrich
Comment Utility
Hello.

This seems to ok up to the point I want to open up the file that has been saved.  It seems to be missing 2 leading characters that make the file legit.  If I open the file up in notepad, then save it, notepad will add those 2 characters to the beginning of the file and then I will be open to open the XML file in IE.  If I just open the saved file in IE, IE will not read it.

I compared the two files in VC++ binary editor and the difference is, the working file has FF EE then the rest of the data.  The corrupt file does not have that FF EE - is there a way to fix this in the .net code?
0
 
LVL 14

Expert Comment

by:ptakja
Comment Utility
I wonder if this is a side effect of the Unicode encoding.  Try changing this line:

Dim objEncoding As Encoding = Encoding.Unicode

To this:

Dim objEncoding As Encoding = Encoding.Ascii

Unicode uses 2-bytes for each character.  And coincidentally, your file is missing 2 bytes.  So this may be the cause of the problem.

Jeff
0
 
LVL 2

Author Comment

by:fishrich
Comment Utility
That worked!  Thanks.
0
 
LVL 14

Expert Comment

by:ptakja
Comment Utility
Glad I could help!

Jeff
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now