Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Convert a string to memorystream to stream to client

Posted on 2004-08-11
5
Medium Priority
?
1,482 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 1000 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: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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