Click here to Skip to main content
14,599,201 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a asp.net project.i am using a file uploader, i want to preview the image in a panel or div what i selected in the fileuploader control, what is the solution?
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

add a httphandler class

<%@ WebHandler Language="C#" Class="ImageHandler" %>

using System;
using System.Web;

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

   public void ProcessRequest (HttpContext context) {
    //Checking whether the imagebytes session variable have anything else not doing anything

       if ((context.Session["ImageBytes"]) != null)
       {
           byte[] image = (byte[])(context.Session["ImageBytes"]);
           context.Response.ContentType = "image/JPEG";
           context.Response.BinaryWrite(image);
       }
   }

   public bool IsReusable {
       get {
           return false;
       }
   }

}



and in the preview button click
protected void btnPreview_Click(object sender, EventArgs e)

   {

       Session["ImageBytes"] = PhotoUpload.FileBytes;

       ImagePreview.ImageUrl = "~/ImageHandler.ashx";

   }



Here PhotoUpload is my File Upload control and ImagePreview is asp:image control.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100