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?

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.