Link to home
Start Free TrialLog in
Avatar of kunasharma
kunasharma

asked on

Load image in report in runtime in ASP.Net

I have to display a logo in crystal report in runtime. I have tried two solutions given in http://www.devx.com/codemag/Article/33658/1954 (Tip 6: Better Handling of Dynamic Images).

In both case i am getting error "cannot obtain value" in following line(detail in code snippet):

rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, False, "")

Need help to solve this. Its very urgent.

Thanks
Dim data As New DataSet()
    Dim row As DataRow
 
Step1 (Passing Image URL into dataset): my code is as follows
Private Sub LoadImgUrl()
        Try
            data.Tables.Add("Image")
            data.Tables("Image").Columns.Add("Name")
 
            row = data.Tables(0).NewRow()
            row(0) = Server.MapPath("DI.bmp")
            data.Tables(0).Rows.Add(row)
 
            rptDoc.Load(Server.MapPath("rptImgUrl.rpt"))
            rptDoc.SetDataSource(data)
 
            Response.Clear()
            Response.Buffer = True
            Response.ClearContent()
            Response.ClearHeaders()
 
            Response.ContentType = "application/pdf"
            rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, False, "")
            
            Response.Flush()
 
            Response.End()
        Catch ex As Exception
 
        End Try
 
    End Sub
--------------
 
Step2 (Storing Image into dataset): my code is as follows
 
Private Sub LoadImgDS()
        Try
            data.Tables.Add("Image")
            data.Tables("Image").Columns.Add("Logo", System.Type.GetType("System.Byte[]"))
 
            Dim fs As New System.IO.FileStream(Server.MapPath("DI.bmp"), System.IO.FileMode.Open, IO.FileAccess.Read)
            Dim br As New System.IO.BinaryReader(fs)
 
            row = data.Tables("Image").NewRow()
            row("Logo") = br.ReadBytes(br.BaseStream.Length)
            data.Tables("Image").Rows.Add(row)
 
            rptDoc.Load(Server.MapPath("rptImgDS.rpt"))
            rptDoc.SetDataSource(data)
 
            Response.Clear()
            Response.Buffer = True
            Response.ClearContent()
            Response.ClearHeaders()
 
            Response.ContentType = "application/pdf"
            rptDoc.ExportToHttpResponse(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Response, False, "")
            br.Close()
            fs.Close()
 
            br = Nothing
            fs = Nothing
        Catch ex As Exception
 
        End Try
    End Sub
--------

Open in new window

SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial