2

I have some sql tables with dynamic columns which i want to export them to xls or csv file using DevExpress ASPxGridViewExporter and ASPxGridView when user clicks Get Data button in my Report.aspx page.

  • Tables are made correctly with true data
  • Page loads successfully and shows data truly

My Problem

When user clicks the button, it downloads a corrupted file with following content,

I searched google, stackoverflow, microsoft support, devexpress support and so many sites, but there was no answer!

any help will be appreciated.

Server Error in '/' Application.        


The stream state of the underlying compression routine is inconsistent.     

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error     and where it originated in the code.       

Exception Details: System.IO.Compression.ZLibException: The stream state of the underlying compression routine is inconsistent.     

Source Error:       

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be     identified using the exception stack trace below.       

Stack Trace:        

[ZLibException: The stream state of the underlying compression routine is inconsistent.]        
   System.IO.Compression.DeflaterZLib.Deflate(FlushCode flushCode) +196     
   System.IO.Compression.DeflaterZLib.ReadDeflateOutput(Byte[] outputBuffer, FlushCode flushCode, Int32& bytesRead) +185        
   System.IO.Compression.DeflaterZLib.System.IO.Compression.IDeflater.GetDeflateOutput(Byte[] outputBuffer) +44     
   System.IO.Compression.DeflateStream.WriteDeflaterOutput(Boolean isAsync) +58     
   System.IO.Compression.DeflateStream.Write(Byte[] array, Int32 offset, Int32 count) +76       
   System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +578        
   System.Web.HttpResponse.UpdateNativeResponse(Boolean sendHeaders) +1272      
   System.Web.HttpResponse.Flush(Boolean finalFlush, Boolean async) +191        
   System.Web.HttpWriter.WriteFromStream(Byte[] data, Int32 offset, Int32 size) +88     
   System.IO.Compression.DeflateStream.PurgeBuffers(Boolean disposing) +142     
   System.IO.Compression.DeflateStream.Dispose(Boolean disposing) +40       
   System.IO.Stream.Close() +26     
   System.IO.Compression.GZipStream.Dispose(Boolean disposing) +42      
   System.IO.Stream.Close() +26     
   System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr) +767        
   System.Web.HttpResponse.FilterOutput() +127      
   System.Web.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +62       
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +98     

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0         

My Questions

  • Why ZLibException thorws?

Here is my codes:

ASP

<%@ Register Assembly="DevExpress.Web.v16.1" Namespace="DevExpress.Web"
    TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.XtraPrinting.v16.1" Namespace="DevExpress.Web"
    TagPrefix="dx" %>

<%@ Register  Assembly="DevExpress.Printing.v16.1.Core, Version=16.1.4.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Printing"
    TagPrefix="dx" %>

<asp:Content ID="Content2" ContentPlaceHolderID="C" runat="Server">
    <div id="divMain" class="main" style="padding: 10px">
        <asp:ObjectDataSource ID="ods" runat="server" TypeName="MySite.Control.CustomTable" SelectMethod="ReadTable">
            <SelectParameters>
                <asp:Parameter Type="Int64" Name="ID" />
            </SelectParameters>
        </asp:ObjectDataSource>

        <dx:ASPxGridView ID="grid" runat="server" ClientInstanceName="grid" AutoGenerateColumns="false"
            KeyFieldName="ID" Width="100%">
            <Columns>
                <!-- Columns Will Be Generated Dynamically -->
            </Columns>
            <SettingsCustomizationWindow Enabled="True" />
            <SettingsBehavior ColumnResizeMode="Control" AllowDragDrop="true" AllowFocusedRow="true" />
            <Settings ShowGroupPanel="True" ShowColumnHeaders="true" ShowFilterBar="Visible"
                ShowFooter="true" ShowGroupFooter="VisibleIfExpanded" ShowGroupButtons="true"
                ShowFilterRow="true" ShowFilterRowMenu="true" />
            <SettingsLoadingPanel Mode="ShowOnStatusBar" />
            <GroupSummary>
            </GroupSummary>
        </dx:ASPxGridView>

        <!-- ASPxGridViewExporter -->
        <dx:ASPxGridViewExporter ID="exporter" runat="server" GridViewID="grid">
        </dx:ASPxGridViewExporter>


        <div style="direction: rtl">
            <asp:DropDownList ID="exportType" runat="server">
                <asp:ListItem Text="XLS" Value="XLS" />
                <asp:ListItem Text="CSV" Value="CSV" />
            </asp:DropDownList>

            <asp:Button ID="btnExport" runat="server" Text="Get Data" OnClick="BtnExportClick" />
        </div>

    </div>


</asp:Content>

C#

protected void BtnExportClick(object sender, EventArgs e)
{
    grid.SettingsDetail.ExportMode = GridViewDetailExportMode.All;
    switch (exportType.SelectedValue)
    {
        case "XLS":
            exporter.WriteXlsToResponse();
            break;
        case "CSV":
            exporter.WriteCsvToResponse();
            break;
        default:
            return;
    }
}
Community
  • 1
  • 1
Rahmat Waisi
  • 1,293
  • 1
  • 15
  • 36

1 Answers1

0

I don't know if you were able to resolve this but in my case it was due to the Telerik Compression (Rad Compression) which was trying to Deflate the output stream. Once I got rid of it in my class declaration issue disappeared.

Another suggestion would be moving the grid control outside of the Update Panel. WriteToResponse methods don't work if the control is inside an update panel.

Ozan Gunceler
  • 1,067
  • 11
  • 20