|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
memory stream XML and unicode problemI 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 **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 > 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 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 > >
SqlDateTime.MinValue, SqlDateTime.MaxValue: WATCH OUT!
IO function in Vb.Net slower than in Vb6.0 Excel ADO question Using a variable to specify the name of a control Datalist/datatable sorting Cannot Get MenuItem's name[Notsolved] Writing E-Mail Notfications VB.NET with ADO.NET compilation error. ComboBox needs help How do I run one project? |
|||||||||||||||||||||||