Home All Groups Group Topic Archive Search About

memory stream XML and unicode problem

Author
29 Mar 2005 9:29 AM
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

Author
29 Mar 2005 3:53 PM
Richard Wilde
**Bump**

Can anyone help me in this matter?
Many Thanks
Richard

Show quoteHide quote
"Richard Wilde" <XXXXi***@rippo.co.ukXXXX> wrote in message
news:%23nprGHENFHA.2420@TK2MSFTNGP10.phx.gbl...
> 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
>
Author
29 Mar 2005 5:28 PM
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
Author
30 Mar 2005 8:19 AM
Richard Wilde
Cor

Thanks. This is perfect

Rippo

Show quoteHide quote
"Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message
news:%23$gmHTINFHA.3928@TK2MSFTNGP09.phx.gbl...
> 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
>
>