Solved

Convert a string to memorystream to stream to client

Posted on 2004-08-11
5
1,478 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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