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..

I am confused ...

the image is already uploaded and saved on the folder

i have a fieldo n my db img and the data type of it is image...

According to your words, you have 2 images.
Wich image do you want to upload, the one in the folder or the one in the DB?

i have only 1 image to upload.. once i uploaded the image all i want is to retreive it and place it on the other form.. i used ashx to hold the uploaded image.. the uploaded image is also save on the folder.. how do i retreive the image to the other from from the folder after they are uploaded..

i am getting an error with the ashx file..
"Unable to cast object of type 'System.String' to type 'System.Byte[]'"

@lolafuertes the one that is on the folder.. but the image that is on the db is the one that is in the folder also.. they are the same..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.