I have been trying to add image in my crystal report.

Jun 3 2017 1:49 AM
I have been trying to Print Id Card With Employee Image and Compay logo in my crystal report. I have able to get the path from database. i placed the path in my crystal report. instead of printing the Employee Photo and Logo, it prints the path.In database i have taken varchar datatype for both photo and logo.
 
this is my c# code 
 
 
 
EmployeeDetailsForIdCardBL bl = new EmployeeDetailsForIdCardBL();
FileName = "Employee IdCard Report";
string empcode = strRequestNo.ToString();
DataSet dsemployeeIdCard = new DataSet();
DataTable dtCommonReportViewCRV1 = new DataTable();
dsemployeeIdCard = bl.GetIndivisaulIdCardForPrint(empcode);
dtCommonReportViewCRV1 = dsemployeeIdCard.Tables[0];
//if (dtCommonReportViewCRV != null)
//{
// dtCommonReportViewCRV1.WriteXmlSchema(Server.MapPath(".") + "\\App_Code\\IdCard.xsd");
//}
rptDoc.Load(Server.MapPath(".") + "\\ID Details.rpt");
//dtCommonReportViewCRV.TableName = "Table1";
string logo = "";
if (dsemployeeIdCard != null)
{
logo = dsemployeeIdCard.Tables[0].Rows[0]["logoFile"].ToString();
}
FileStream fs = new FileStream(Server.MapPath(@"./photos/" + logo), FileMode.Open);
BinaryReader br = new BinaryReader(fs);
byte[] pic = br.ReadBytes((int)fs.Length);
br.Close();
dtCommonReportViewCRV1.Columns.Add("logoFile1", typeof(byte[]));
for (int i = 0; i < dtCommonReportViewCRV.Rows.Count; i++)
{
dtCommonReportViewCRV1.Rows[i]["logoFile1"] = pic;
}
string Empphoto = "";
if (dsemployeeIdCard != null)
{
Empphoto = dsemployeeIdCard.Tables[0].Rows[0]["empphoto"].ToString();
}
string strEmpphotoPath = Server.MapPath(@"./EmpPhotos/" + Empphoto);
FileStream fs1 = new FileStream(strEmpphotoPath, FileMode.Open);
BinaryReader br1 = new BinaryReader(fs1);
byte[] photo = br1.ReadBytes((int)fs1.Length);
br1.Close();
if (dsemployeeIdCard != null && dsemployeeIdCard.Tables.Count > 0 && dsemployeeIdCard.Tables[0].Rows.Count > 0)
{
dsemployeeIdCard.Tables[0].Columns.Add("EmployeePhoto", typeof(byte[]));
for (int i = 0; i < dsemployeeIdCard.Tables[0].Rows.Count; i++)
{
dsemployeeIdCard.Tables[0].Rows[i]["EmployeePhoto"] = photo;
}
}
if (dtCommonReportViewCRV1.Rows.Count > 0)
{
rptDoc.SetDataSource(dtCommonReportViewCRV1);
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = strSAPDATABASESERVER;
crConnectionInfo.DatabaseName = strDataBaseName;
crConnectionInfo.UserID = strSAPDATABASEUSERID;
crConnectionInfo.Password = strSAPDATABASEUSERID;
TableLogOnInfo crTableLogoninfo = new TableLogOnInfo();
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in rptDoc.Database.Tables)
{
crTableLogoninfo = CrTable.LogOnInfo;
crTableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crTableLogoninfo);
}
PrintReportViewCRV.ReportSource = rptDoc;
}
byteArray = null;
oDocStream = rptDoc.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byteArray = new byte[oDocStream.Length];
oDocStream.Read(byteArray, 0, Convert.ToInt32(oDocStream.Length - 1));
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ".pdf");
Response.BinaryWrite(byteArray);
Response.End();
rptDoc.Close();
rptDoc.Dispose();
 

Answers (2)