i want to export pic from gridview to pdf file. it is showing error Error1Cannot convert type 'string' to 'byte[]'. here is code for reference
int i = 0;
string Reg = null;
string name = null;
string fname = null;
string Cls = null;
string Sec = null;
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Report-StuExamResultCard-" + ddlClass.SelectedItem.ToString() + ".pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Document doc = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
try
{
DataTable dt = new DataTable("GridView_Data");
foreach (GridViewRow row in GridView1.Rows)
{
Reg = row.Cells[1].Text;
name = row.Cells[2].Text;
fname = row.Cells[3].Text;
Cls = row.Cells[4].Text;
Sec = row.Cells[5].Text;
byte[] bytess = ((byte[])row.Cells[5].Text;
PdfPTable table = new PdfPTable(8);
table.DefaultCell.Padding = 10f;
table.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
table.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
table.HorizontalAlignment = Element.ALIGN_CENTER;
table.TotalWidth = 500f;
table.LockedWidth = true;
PdfPTable nested = new PdfPTable(4);
float[] width = new float[] { 0.1f, 0.1f, 0.1f, 0.1f };
nested.SetWidths(width);
nested.DefaultCell.BackgroundColor = iTextSharp.text.Color.WHITE;
nested.DefaultCell.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nested.DefaultCell.Padding = 10f;
nested.AddCell(new Phrase("Reg No.", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(Reg, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Session", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(ddlSession.SelectedItem.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Student Name", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(name, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Assessment Term", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(ddlExam.SelectedItem.ToString(), FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Father Name", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(fname, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Attendance", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase("", FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Class", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(Cls, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
nested.AddCell(new Phrase("Section", FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)));
nested.AddCell(new Phrase(Sec, FontFactory.GetFont(FontFactory.HELVETICA, 8)));
PdfPCell nesthousing = new PdfPCell(nested);
nesthousing.BackgroundColor = iTextSharp.text.Color.WHITE;
nesthousing.BorderColor = new iTextSharp.text.Color(191, 208, 247);
nesthousing.Colspan = 7;
nesthousing.Padding = 0f;
table.AddCell(nesthousing);
iTextSharp.text.Image imag = iTextSharp.text.Image.GetInstance(bytess);
imag.ScaleToFit(45F, 50F);
PdfPCell bottom = new PdfPCell();
bottom.Padding = 5f;
bottom.BackgroundColor = iTextSharp.text.Color.WHITE;
bottom.BorderColor = new iTextSharp.text.Color(191, 208, 247);
bottom.HorizontalAlignment = 1;
table.AddCell(bottom);
}
doc.Close();
Response.Write(doc);
Response.End();
}
catch (Exception)
{
throw;
}
finally
{
doc.Close();
}