You must Sign In to post a response.
  • Category: .NET

    How to shows images in Reports


    i am using Crystal report In windows application show the image from byte array datatype.
    I tried through OLE Object Also, but here am no getting how to configure image file to OLE Object. Could u please give me solution .
  • #767071
    Use 'DataTable' add data column with datatype as 'Image', use filestream class to read image from Byte, finally add datatable to crystal report using 'SetDataSource' property
    I got following code

    try {
    // here i have define a simple datatable inwhich image will recide
    DataTable dt = new DataTable();
    // object of data row
    DataRow drow;
    // add the column in table to store the image of Byte array type
    dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"));
    drow = dt.NewRow;
    // define the filestream object to read the image
    FileStream fs;
    // define te binary reader to read the bytes of image
    BinaryReader br;
    // check the existance of image
    if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg")) {
    // open image in file stream
    fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg", FileMode.Open);
    else {
    // if phot does not exist show the nophoto.jpg file
    fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open);
    // initialise the binary reader from file streamobject
    br = new BinaryReader(fs);
    // define the byte array of filelength
    byte[] imgbyte = new byte[fs.Length + 1];
    // read the bytes from the binary reader
    imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
    drow(0) = imgbyte;
    // add the image in bytearray
    // add row into the datatable
    // close the binary reader
    // close the file stream
    CrystalReport1 rptobj = new CrystalReport1();
    // object of crystal report
    // set the datasource of crystalreport object
    CrystalReportViewer1.ReportSource = rptobj;
    //set the report source
    catch (Exception ex) {
    // error handling
    Interaction.MsgBox("Missing 10157.jpg or nophoto.jpg in application folder");
    // run the application to view image in report

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #767079
    You need to add the following in the <httpHandlers> section of Web.Config. Then and Then only you can view the images in crystal report.

    <addverb="GET"path="CrystalImageHandler.aspx"type="CrystalDecisions.Web.CrystalImageHandler, CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" />

    DataTable dt= new DataTable();
    ReportDocument crystalRpt = new ReportDocument();
    SqlCommand cmd = new SqlCommand("select * from TableWithImageColumn");
    using (SqlConnection sqlCon = new SqlConnection("YourConnectionString"))
    using (SqlDataAdapter da = new SqlDataAdapter())
    cmd.Connection = qlCon;
    sda.SelectCommand = cmd;
    CrystalReportViewer1.ReportSource = crystalRpt;

  • Sign In to post your comments