【发布时间】:2016-12-22 12:26:58
【问题描述】:
我有一些带有动态列的 sql 表,当用户单击我的 Report.aspx 页面中的 Get Data 按钮时,我想使用 DevExpress ASPxGridViewExporter 和 ASPxGridView 将它们导出到 xls 或 csv 文件.
- 使用真实数据正确制作表格
- 页面加载成功,真实显示数据
我的问题
当用户点击按钮时,它会下载一个带有以下内容的损坏文件,
我搜索了google、stackoverflow、microsoft support、devexpress support等很多网站,但都没有答案!
任何帮助将不胜感激。
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
我的问题
- 为什么是
ZLibExceptionthorws?
这是我的代码:
平均售价
<%@ 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;
}
}
【问题讨论】:
标签: c# asp.net exception export-to-excel aspxgridview