memory stream XML and unicode problem

R

Richard Wilde

Hi
I have found on the internet a way to write out an xml file direct to the
browser so as the save as box is displayed on a click of a button. All works
well apart with non unicode data. However as soon as I have unicode data I
only get an empty file (well a file with blanks or I assume spaces). This
must be something to do that unicode data is 2 bytes and my code does not
allow for that as the conversion of byte only takes the top byte.

I have tried without success to find out how to solve this problem. Can
anyone help?

Many thanks
Richard


Dim ds As DataSet
Dim fStream As New System.IO.MemoryStream

'fill the dataset
ds = DBTools.GetExportDataForReport()

'Write dataset to the memory stream
ds.WriteXml(fStream)

'write out memory stream to disk
Dim b(CType(fStream.Length, Int32)) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition", "attachment;filename=export.xml")
fStream.Read(b, 0, CType(fStream.Length, Int32))
Response.BinaryWrite(b)
Response.End()
fStream.Flush()
fStream.Close()
fStream = Nothing
 
C

Cor Ligthert

Richard,

Is this what you want to achieve?
I made a test dataset.

\\\
Dim ds As New DataSet
Dim dt As New DataTable
ds.Tables.Add(dt)
dt.Columns.Add()
dt.LoadDataRow(New Object() {"Hello"}, True)
Dim sw As New System.IO.StringWriter
ds.WriteXml(sw)
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/unknown"
Response.AddHeader("Content-Disposition", "attachment;filename=export.xml")
Response.Write(sw.ToString)
Response.End()
sw.Close()
///

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top