Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 100.7k

How Do I Get Ride To Select Image Each Time When Record save

Jul 3 2015 12:45 AM
i have a form in which i can save data about employee
including image.image is saving/retrieve properly ,problem is
that when i retrieve image is time then save or update the record
without selecting image ,image is not going to save. i am using following code to save image
Hide Copy 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;                 }    
and retriving image by
Hide Copy Code
  empPicture.ImageUrl = string.Format("EmpPicture.ashx?id={0}", emp.Id);
problem is when image is retrieve 1st time then save again it does not save in db,

Answers (1)