In my Crystal Report I need To add Header Image from specific Folder Path, for that I done Below Code
private void AddImage_ProdfailReport()
{
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 + "Footer.Jpg"))
{
// open image in file stream
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Footer.Jpg", FileMode.Open);
}
else
{
// if phot does not exist show the nophoto.jpg file
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Footer.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
CreRe_ProdFail rptobj = new CreRe_ProdFail();
// object of crystal report
rptobj.SetDataSource(dt);
// set the datasource of crystalreport object
crv1.ReportSource = rptobj;
//set the report source
}
catch (Exception ex)
{
// error handling
MessageBox.Show("Missing Footer.jpg in application folder");
}
// run the application to view image in report
}
I created a field in a datatable of the dataset and change the DataType to System.Byte()
Then I drag this field to the report But its Showing An Error "This Field name is not known" , while Opening Report.. I am not getting what is Problem Please help me in it.