Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 100.6k

how to show image on the webform

Apr 10 2015 5:49 PM
i have a form to save employee information including employee image,image is saving properly using following code.

 Employee.ImgBody = (Employee.ImgBody == null) ? new byte[0] : Employee.ImgBody;
 //Image saving code Byte[] imgByte = null;
 if (txtEpPicture.HasFile && txtEpPicture.PostedFile != null)
{
//To create a PostedFile
HttpPostedFile File = txtEpPicture.PostedFile;
//Create byte Array with file len
imgByte = new Byte[File.ContentLength];
//force the control to load data in array
File.InputStream.Read(imgByte, 0, File.ContentLength);
Employee.ImgBody = imgByte;
}
now i want to show that image when user select any employee and also want to update that image if user need. i want to show image into the form by using following code
empPicture.ImageUrl = string.Format("EmpPicture.ashx?id={0}", Employee.Id); 
i have search and try different solution from the google,but all in vain,image is in db in the form of varbinary.

Answers (2)