Good day,
I am having problem with displaying my image on the my form.. the image is already uploaded and saved on the folder. so all i want is to retreive it and place it on the other form. This is web application
here is my code
private void GetImages()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["myConn"].ToString());
conn.Open();
try
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_GetImages";
cmd.Parameters.Add("@id", SqlDbType.Int, 0).Value = lblPresID.Text;
cmd.ExecuteNonQuery();
Session["ImageBytes"] = "~/Candidates_Images"; //FileUpload1.FileBytes;
Image2.Visible = true;
//Image2.ImageUrl = "~/Candidates_Images";
Image2.ImageUrl = "~/Handler.ashx";
}
catch (Exception err)
{
string error = err.ToString();
}
finally
{
conn.Close();
}
}
for retreiving image on the form.. i created Handle.ashx for handling my image that was uploaded...
here is my code for handle.ashx
public void ProcessRequest(HttpContext context)
{
if ((context.Session["ImageBytes"]) != null)
{
byte[] image = (byte[])(context.Session["ImageBytes"]); // the error is here
context.Response.ContentType = "Candidates_Images";
context.Response.BinaryWrite(image);
}
}
public bool IsReusable
{
get
{
return false;
}
}
i am getting an error
Unable to cast object of type 'System.String' to type 'System.Byte[]'
i have a fieldo n my db img and the data type of it is image...
how could i retreive that imge to the form..