我有下面的代码
它的功能是使用 CrystalReports 从屏幕上的报告中加载数据。
Dim strExportFile As String
strExportFile = "ReportReajustesAplicados.pdf"
Dim s As System.IO.MemoryStream = relat.ExportToStream(ExportFormatType.PortableDocFormat)
With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("Content-Disposition", "inline; filename=" & strExportFile)
.BinaryWrite(s.ToArray)
.End()
End With
当我提取数据时。
我有以下错误
无法将“FileStreamDeleteOnClose”类型的对象转换为“System.IO.MemoryStream”类型。
我尝试使用 System.IO.Stream,提取工作但不会在屏幕上显示数据,因为“.BinaryWrite (s.ToArray)”不接受 ToArray 方法。
注意:当我把
#if DEBUG Then
CrystalReportViewer1.ReportSource = relat
CrystalReportViewer1.DataBind ()
Exit Sub
If #End
作品
我需要这个才能工作,但在 Release模式下。
帮我
最佳答案
我在以下位置找到了解决方案:
https://archive.sap.com/discussions/thread/3322762
正如SAP家伙回答的那样:
“这是设计使然,我们从未完全支持导出到 MemoryStream。
唯一的选择是不使用 MemoryStream,这不会改变。”
所以解决办法是更换内存流 与 流 并发送至 字节 数组如下:
Dim strExportFile As String
strExportFile = "ReportReajustesAplicados.pdf"
Dim s As System.IO.Stream = relat.ExportToStream(ExportFormatType.PortableDocFormat)
Dim b(s.Length) As Byte
s.Read(b, 0, CInt(s.Length))
With HttpContext.Current.Response
.ClearContent()
.ClearHeaders()
.ContentType = "application/pdf"
.AddHeader("Content-Disposition", "inline; filename=" & strExportFile)
.BinaryWrite(b)
.Flush()
.SuppressContent = True
HttpContext.Current.ApplicationInstance.CompleteRequest()
End With
关于vb.net - 错误显示 pdf Crystal Report vb.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31619138/