vb.net - 错误显示 pdf Crystal Report vb.net

标签 vb.net visual-studio-2010 crystal-reports

我有下面的代码
它的功能是使用 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/

相关文章:

vb.net - Windows 服务应用程序中自托管 ASP.NET Web API 的问题

html - 传递参数并引用#div

c# - VS2010 : Code analysis warning CA2000. 对象未沿所有异常路径进行处理

.net - 开发时我应引用哪个版本的 Crystal Reports(32 位或 64 位)?

asp.net - CrystalDecisions,.Shared.dll 版本控制问题

javascript - 更改为服务器端时如何获取标签文本?

.net - 嵌入互操作类型时引用 SQLiteCommand 类无效

c# - Activator.CreateInstance 导致 nunit 锁定,从而阻止 visual studio 构建

c# - 使用 COM 从注册表加载类适用于 ToolsVersion ="2.0"但因 ToolsVersion ="4.0"而失败

visual-studio-2010 - Visual Studio 2010 中的 Crystal 报表