Solved

Convert a string to memorystream to stream to client

Posted on 2004-08-11
5
1,480 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
[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
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
ptakja earned 250 total points
ID: 11776985
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
ID: 11778640
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
ID: 11783275
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
ID: 11785757
That worked!  Thanks.
0
 
LVL 14

Expert Comment

by:ptakja
ID: 11785818
Glad I could help!

Jeff
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

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