1

我将 VS-2008 用于 asp.net Web 应用程序。但是,我在 VS 2005 中开发了我的报告。(我正在重用在其他项目中开发的一些报告)。

除了不显示图像字段外,报告工作正常。图像字段是数据库中的“VARBINARY(MAX)”字段。请注意,当我将 Crystal Report 导出为 .pdf 时,图像会显示在 .pdf 文件中。

(* 我能够在“Firebug”中看到图像 url,但收到消息“加载图像失败”)

我正在使用“TypedDataset”作为 Crystal Report 的数据源。

我从数据库中获取数据并执行“DataSet.WriteXML(filename,WriteMode.WriteSchema)”

这是代码: -

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim rgx As Regex = New Regex("[^a-zA-Z0-9 -]")
    strComp = rgx.Replace(strComp, "")
    strFile = "tempXML" + strComp + ".xml"
    Dim dsTemp As New DataSet
    dsTemp.Clear()
    dsTemp.Tables.Clear()
    Dim rptengine As New CrystalDecisions.CrystalReports.Engine.ReportDocument
    rptengine.Load(Session("rptname"))
    sdate = CType(Session("sdate"), Date)
    edate = CType(Session("edate"), Date)
    rptHeading = Session("rptHead")

    If IO.File.Exists(Server.MapPath("~/" + strFile)) Then
        dsTemp.ReadXml(Server.MapPath("~/" + strFile), XmlReadMode.ReadSchema)
        'IO.File.Delete(Server.MapPath("~/" + strFile))
        Try
            If Session("rptname").ToString.Substring(Session("rptname").ToString.LastIndexOf("\") + 1) _
                = "Rptemp.rpt" Then
                Dim dsReport As New DDL.dsEmpList
                dsReport.Tables("dtEmpList").Merge(dsTemp.Tables(0))
                rptengine.SetDataSource(dsReport.Tables(0))
            ElseIf Session("rptname").ToString.Substring(Session("rptname").ToString.LastIndexOf("\") + 1) _
                = "rptDailyAttendance.rpt" Then
                Dim dsReport As New DDL.dsDailyReoprt
                dsReport.Tables("dtDailyReport").Merge(dsTemp.Tables(0))
                rptengine.SetDataSource(dsReport.Tables(0))
            End If
        Catch ex As Exception
            ShowMsg1("Exception : " & ex.Message)
        End Try


        '**********************assigning CR-ParameterFields*****************************
        Dim crParameterFieldDefinitions As ParameterFieldDefinitions
        Dim crParameterFieldDefinition As ParameterFieldDefinition
        Dim crParameterValues As ParameterValues
        Dim crParameterDiscreteValue As ParameterDiscreteValue
        Dim parameterToDefine As Boolean = False

        crParameterFieldDefinitions = rptengine.DataDefinition.ParameterFields

        For Each crParameterFieldDefinition In crParameterFieldDefinitions
            crParameterDiscreteValue = New ParameterDiscreteValue
            crParameterValues = crParameterFieldDefinition.CurrentValues
            Select Case crParameterFieldDefinition.Name
                Case "sdate"
                    parameterToDefine = True
                    crParameterDiscreteValue.Value = sdate
                Case "edate"
                    parameterToDefine = True
                    crParameterDiscreteValue.Value = edate
                Case "heading"
                    parameterToDefine = True
                    crParameterDiscreteValue.Value = rptHeading
                Case Else
                    parameterToDefine = False
            End Select

            If parameterToDefine Then
                Try
                    crParameterValues.Add(crParameterDiscreteValue)
                    crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
                Catch ex As Exception
                    objdata.writelog(ex.Message, "frmRptEngine", "frmRptEngine_Load", Server.MapPath("~/Reports"))
                    ShowMsg1("Error in report generation.")
                    Exit Sub
                End Try
            End If
        Next

        rptViewer.ReportSource = Nothing
        rptViewer.ReportSource = rptengine
        rptViewer.Enabled = True
        rptViewer.DataBind()
    Else
        ShowMsg1("Invalid attempt.")
    End If
End Sub
4

1 回答 1

2

对于我们这些运行从 .Net 4.0 或更低版本到 4.5+ 的迁移项目的人,我进行了观察。似乎如果包含查看器的页面位于子目录中,那么图像 url 是相对于该页面而不是 Web 应用程序的根目录生成的。例如,如果您的页面是 /gl/accounts.aspx,则图像可能是 /gl/crystalimagehandler.aspx 等 解决此问题的快速方法是将处理程序映射更改为以 crystalimagehandler.aspx 结尾的通配符,或将以下代码放入 Global .asax

protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var p = Request.Path.ToLower().Trim();
            if (p.EndsWith("/crystalimagehandler.aspx") && p!= "/crystalimagehandler.aspx")
            {
                var fullPath=Request.Url.AbsoluteUri.ToLower();
                var index = fullPath.IndexOf("/crystalimagehandler.aspx");
                Response.Redirect(fullPath.Substring(index));
            }
        }
于 2014-09-22T23:01:45.217 回答