Tuesday, August 4, 2009

To display images(jpg,bitmap) in an crystal report in asp.net and also i included how to produce crystal report in pdf format


It's easy to display images in crystal report of asp.net .The method is as follows:
1. create an XSD Schema in ' appcode' folder ,In the XSD Schema you can create datatables with fields
example :
consider
create table image_list
(
image_id NUMBER(5) not null,
PHOTO BLOB
)

then select these fields using select query in your coding side.
example:
Imports system.data Imports System.Data.OracleClient
Imports CrystalDecisions.Shared 
Imports CrystalDecisions.CrystalReports.Engine 
Partial Class image_list    
 Inherits System.Web.UI.Page   
  Dim oh As New helper.oracle.OracleHelper 
    Dim report As New ReportDocument  
   Dim export As New IO.MemoryStream  
   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load     
     Dim dt As DataTable = oh.ExecuteDataSet("select image_id,photo from image_list ").Tables(0)    
     report.Load(Server.MapPath("image_list.rpt"), OpenReportMethod.OpenReportByTempCopy)
         report.SetDataSource(dt)
          export = report.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
         Response.Clear()      
   Response.Buffer = True    
     Response.ContentType = "application/pdf"    
     Response.BinaryWrite(export.ToArray())    
      Response.End()     
     Me.CrystalReportViewer1.ReportSource = export
      End Sub
 End Class 
Now create an XSD Schema in Appcode as given below






The crystal report is designed as per given instruction above ,Note while creating xsd schema datatable be alert on the datatype of the image feild i mean blob field its data type must be in byte[].then only while you export these datatables into crystal report you can display the images otherwise it will not.
Bilumon V B  ,email - bilumon@gmail.com
 

No comments:

Post a Comment