Start New Discussion within our Software Development Community

Hi,

I have some problem that I can display the image in picturebox before save into database when browse but after browse, the image path is lost in fileupload and I unable to save the path into database. Can I display and image in picturebox , but the path still leave it in fileupload? Please advice.Thanks

Below is my example code of display image

Handler1

 public class Handler1 : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            if ((context.Session["ImageBytes"]) != null)
            {
                byte[] image = (byte[])(context.Session["ImageBytes"]);
                context.Response.ContentType = "image/JPG";
                context.Response.BinaryWrite(image);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

Webform

namespace imageDisplayTest
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            UpLoadAndDisplay();
        }

        private void UpLoadAndDisplay()
        {
            Session["ImageBytes"] = PhotoUpload.FileBytes;
            ImagePreview.ImageUrl = "~/Handler1.ashx";
        }
    }

}

I really don't have much knowledge here, but may I ask you something.

Why don't you assign the fileupload to a string, and have the string hold the value? Or am I misunderstanding this?

This article has been dead for over six months. Start a new discussion instead.