Home > ASP.Net > Creating Image Thumbnails in ASP.NET

Creating Image Thumbnails in ASP.NET

Hi all ,

try this example to Creating image thumbnails in ASP.NET

1) Open VS2008 and create a new website and add new Web page

2) Add new folder inside project and name it Upload which will upload image in it

3) From Toolbox add Fileupload and button and two Images controls

        Choose an image to upload
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:Button ID="btn_Upload" runat="server" onclick="btn_Upload_Click" Text="Upload" />
        Original image</p>
        <asp:Image ID="Image1" runat="server" />
        Thumbnail image</p>
        <asp:Image ID="Image2" runat="server" />

and in code behind :-

    protected void btn_Upload_Click(object sender, EventArgs e)
        string target = Server.MapPath("~/Upload");
        System.Drawing.Image.GetThumbnailImageAbort thumbnailImageAbortDelegate = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
        if (FileUpload1.HasFile)
            FileUpload1.SaveAs(System.IO.Path.Combine(target, FileUpload1.FileName));
            using (System.Drawing.Bitmap originalImage = new System.Drawing.Bitmap(FileUpload1.PostedFile.InputStream))
                using (System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(80, 80, thumbnailImageAbortDelegate, IntPtr.Zero))
                    thumbnail.Save(System.IO.Path.Combine(target, "thumb_" + FileUpload1.FileName));
            Image1.ImageUrl = "Upload/" + FileUpload1.FileName;
            Image2.ImageUrl = "Upload/" + "thumb_" + FileUpload1.FileName;
    public bool ThumbnailCallback()
        return false;

Hope this helps
Good Luck

Categories: ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: