I have a utility method (below) that has always served me well. After databinding a report control, I pass the control to this and it renders the report as a PDF.
I recently upgraded to .NET 4.0 and the new 2010 report viewer control (10.0.0.0). Now it throws the error (below) if the recordset (dataset) I pass to the reportviewer doesn't have any data.
Any ideas? Thanks!
ERROR (top 5):
[InvalidOperationException: (processing): ScalableList: Index 0 outside 开发者_JS百科the allowed range [0::-1]] Microsoft.ReportingServices.Diagnostics.Utilities.DefaultRSTraceInternal.Assert(Boolean condition, String componentName, String message) +176 Microsoft.ReportingServices.OnDemandProcessing.Scalability.ScalableList1.get_Item(Int32 index) +212 Microsoft.ReportingServices.Rendering.HPBProcessing.PageStructStaticMemberCell.AddToPageCHContent(List
1 rowHeights, ScalableList`1 columnInfo, Int32 rowIndex, Int32 colIndex, Boolean isLTR, RPLWriter rplWriter, PageContext pageContext, Double pageLeft, Double pageTop, Double pageRight, Double pageBottom, RepeatState repeatState, Boolean& hasLabels) +60 Microsoft.ReportingServices.Rendering.HPBProcessing.Tablix.AddToPage(RPLWriter rplWriter, PageContext pageContext, Double pageLeft, Double pageTop, Double pageRight, Double pageBottom, RepeatState repeatState) +781
UTILITY METHOD:
private static void renderReportAsPDF(ReportViewer reportViewer, HttpResponse response) {
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string reportName = reportViewer.LocalReport.DisplayName;
byte[] bytes = reportViewer.LocalReport.Render("PDF", null, out mimeType, out encoding,out extension, out streamids, out warnings);
response.Clear();
response.ContentType = mimeType;
response.ContentEncoding = System.Text.Encoding.UTF32;
response.BinaryWrite(bytes);
response.End();
}
Opening the rdlc file in VS2010 and having it upgrade the format of the file fixed the problem. Prior to .NET 4.0, the reports ran fine with no recordset in the old 2008 format.
精彩评论