views:

33

answers:

1

I like to compress the xmldata before the data is provided to the client as an excel file. I am trying to compress and deliver it as a .zip file. its not working Here's my code below. Please help

I tried compressing it, converting it to bytes etc etc. The issue with below code is, the XSL transformation is not happening properly and the output excel file is raw xml with some .net exception at the end. (that's what I see on the .xls file that's downloaded at the end) Before I started working on compression my below code was working fine that gives properly formatted excel file from the xml input. the excel file is so nice you can't even tell it was from XML. pLEASE HELP with compression

 Dim attachment As String = "attachment; filename=DataDownload.xls"
        Response.ClearContent()
        Response.AddHeader("content-disposition", attachment)
        Response.ContentType = "application/vnd.ms-excel"
        'Response.ContentType = "text/csv"

        Response.Charset = ""
        Dim ds As New DataSet()

        Dim objXMLReader As XmlReader
        objXMLReader = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteXmlReader(ConnectionString, CommandType.StoredProcedure, "SPName")

        ds.ReadXml(objXMLReader)

        Dim xdd As New XmlDataDocument(ds)
        Dim xt As New XslCompiledTransform()
        'xt.Transform(xdd, Nothing, Response.OutputStream)

        Dim bytearr() As Byte
        bytearr = System.Text.Encoding.Default.GetBytes(xdd.OuterXml)

        Dim objMemStream As New MemoryStream()
        objMemStream.Write(bytearr, 0, bytearr.Length)
        objMemStream.WriteTo(Response.OutputStream)
        xt.Transform(xdd, Nothing, Response.OutputStream)

        Response.End()
+1  A: 

Why you don't use XLSX-Format instead of XLS? It is already XML-Data compressed in a ZIP file. You can rename a XLSX file to ZIP to verify this.

Updated: By the way, ContentType in the case should be "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" instead of "application/vnd.ms-excel".

Oleg