How to save image as binary data in database using jquery in asp.net and also i want to retrieve the image on the current page while click on a button. If any one can help me please. Thanks in advance. Here I attached same I done using cs page but I want to do with jquery. Please help me.
How to save image as binary data in database using jquery?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Susovan Biswas17 pointsPosted Oct 12, 2015, 2:05 AM EDT
HttpFileCollection hfc = HttpContext.Current.Request.Files; if(hfc.Count > 0) { for(int i = 0; i< hfc.count; i++) { HttpPostedFile hpf = hfc[i]; string path = HttpContext.Current.Server.MapPath("Path to save the http posted file"); string imageName = hpf.FileName; InsertPic(imageName); } }private void InsertPic(string imagename) { try { string path = HttpContext.Current.Server.MapPath("Path where you saved the http posted file"); FileStream fsImage = new FileStream(path + @imagename, FileMode.Open, FileAccess.Read); //a byte array to read the image byte[] imgdata = new byte[fsImage.Length]; fsImage.Read(imgdata, 0, System.Convert.ToInt32(fsImage.Length)); string qry = "INSERT INTO TableName(imageField)VALUES(@imageField)"; SqlCommand cmd = new SqlCommand(qry, SqlConnection); cmd.Parameters.Add("@imageField", SqlDbType.VarBinary).Value = imgdata; SqlConnection.Open(); cmd.ExecuteNonQuery(); fsImage.Dispose(); System.IO.File.Delete(HttpContext.Current.Server.MapPath("Path where you saved the http posted file") + imagename); } catch (Exception ex) { } finally { SqlConnection.Close(); } }