I am not able to see any image on Crystal Report at Run time.
So how can I load any image which is saved in local disk so
that it can be viewed at Runtime in Crystal reports?

Answer Posted / vishu

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
dt.Rows.Add(drow);
// add row into the datatable
br.Close();
// close the binary reader
fs.Close();
// close the file stream
CrystalReport1 rptobj = new CrystalReport1();
// object of crystal report
rptobj.SetDataSource(dt);
// 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");
}

Is This Answer Correct ?    7 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Suppose I have a crystal report with a linked subreport as well. Is there any way not to print the current record on the main report if no records are returned from the subreport?

657


Explain the various components in crystal reports?

774


How to access crystal reports in .net?

696


How to open subreport in new ie window using hyperlink button. I used target=new; in the formula field. But it overrides the main window and show the report?

693


What are field expressions and what are the diff types? (I looked this up in the internet and never found anything with regards to types of field expressions)?

683






Where can we find the log file generated when we run a crystal report?

703


How can we improve the performance of a crystal report?

695


Explain reporter footer contents are move depend the page footer values?

638


Explain basic steps required to display a simple report in crystal?

666


hi... i've two crystal reports one is in D: drive name employee.rpt with 5 textobject and another report is in E: drive name employee.rpt with 15 textobject... now i want to write a program to overwrite the D drives report with E drives reports i.e i want to replace the 5 textobject with 15 textobject.. overwriting the reports while it is executing .. is there any code for it please help me.. its urgent..

2696


hi.. i've one crystal report. i want the report header as "employee database". i dont want to right click->insert and goto text object and insert. i've one aspx page and aspx.cs page also. now i want the "employee database" header to be printed from .cs file. i dont want to pass by parameter also.. i.e is there any option in .cs file something like ReportDocument myreport = new ReportDocument(); myreport.Load(MapPath("~/" + "emp.rpt")); myReport.Reportheader="Employee database"; i hope u have understood this. only thing is from .cs file i want to print the header as employee database. i dont want by passing parameter also... please help....

2468


How the data expert of flash object(after inserting flash object_right click-data expert) is useful in crt?

1325


Where is the image located, after youve placed it on the report?

676


What all performance improvement techniques used in crystal reports? (Particularly cr xi)?

668


Is there a size limit to creating a Crystal Report? If I run a statement report for all customers it will crash if there are too many customers. I can print all the statements if I select them in batches, but if trying to print all at once Crystal will crash after a few minutes.

960