Introduction
This article will display the image in crystal report viewrBackground
Using the code
Simply open the source code in 2003.
try {
DataTable dt = new DataTable();
DataRow drow;
dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"));
drow = dt.NewRow;
FileStream fs;
BinaryReader br;
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg")) {
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "10157.Jpg", FileMode.Open);
}
else {
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open);
}
br = new BinaryReader(fs);
byte[] imgbyte = new byte[fs.Length + 1];
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
drow(0) = imgbyte;
dt.Rows.Add(drow);
br.Close();
fs.Close();
CrystalReport1 rptobj = new CrystalReport1();
rptobj.SetDataSource(dt);
CrystalReportViewer1.ReportSource = rptobj;
}
catch (Exception ex) {
Interaction.MsgBox("Missing 10157.jpg or nophoto.jpg in application folder");
}
Remember if you are using c# the paste the above code in button click event
Points of Interest
In this article you will be also able to convert the image into byte array
History
In this project after clicking the button the action are performed you are free to modify as per your requirement
Feel free for any querrrrrries.
enjoy .net