Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,

I am using following code to display an image on a CrystalReport in my web project using embedded crystal reports of VS 2008.

At design time I used a DataSet and Data table with the same schema as the run-time DataTable 'newData'.

C#
customerReport = new ReportDocument();
string reportPath = Server.MapPath("CrystalReport.rpt");
customerReport.Load(reportPath);

            DataTable newData = new DataTable();
            newData.Columns.Add("SNo", System.Type.GetType("System.String"));
            newData.Columns.Add("Name", System.Type.GetType("System.String"));
            newData.Columns.Add("Tele", System.Type.GetType("System.String"));
            newData.Columns.Add("Image", System.Type.GetType("System.Byte[]"));
            DataRow dr = newData.NewRow();
            dr[0] = "Trying once";
            dr[1] = "Trying Again";
            dr[2] = "Still No Clue";
            string picPath = Server.MapPath("EmployeeImage/SomeImage.jpg");
                FileStream fs = new FileStream(picPath, FileMode.Open, FileAccess.Read);
                BinaryReader br = new BinaryReader(fs);
                byte[] imgByte = new byte[fs.Length + 1];
                imgByte = br.ReadBytes(Convert.ToInt32(fs.Length) );
                dr[3] = imgByte;
                newData.Rows.Add(dr);
                br = null;
                fs.Close();
                fs = null;
                customerReport.Database.Tables[0].SetDataSource(newData );
                crystalReportViewer.ReportSource = customerReport;


However, no image is displayed in the CrystalReport. I confirmed that the image field in the datatable is filled with the binary data.

Can anyone help me?

Thanks in Advance.

Regards,

GeoNav
Posted
Updated 25-May-11 19:07pm
v3

1 solution

Try:
1. byte[] imgByte = new byte[fs.Length];
2. customerReport.SetDataSource(newData);

Refer, to display images, have a look at these:
How to dynamically load images in Crystal Reports using Visual Studio 2005[^]
Crystal Reports: How to Display Images in a Crystal Report[^]
Image in Crystal Reports[^]
 
Share this answer
 
Comments
GeoNav 26-May-11 10:49am    
Thanks for the tip. Unfortunately, it did not work. One good thing to see is that the picture object changes the size based on the size of the image I am trying to see. But there is no image.
Any other suggestions?
PS: It is actually disgusting to see that the solution is not working, even though the same lines of codes recommended by many.....
Sandeep Mewara 26-May-11 11:07am    
I can understand! :)

Small things at times give a lot of pain. Will share across if I find/see anything else that might be of some help.
GeoNav 27-May-11 13:32pm    
Is it possible for you to send me a small sample project of yours, so that I can compare other aspects, which might have led to me current situation?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900