?
Solved

Convert a string to memorystream to stream to client

Posted on 2004-08-11
5
Medium Priority
?
1,481 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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 …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

770 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