Create Thumbnail in C#


This is very simple class that I used to generate thumbnail of images. You just pass it file name. It generate the thumbnail from file and store it in thumbnail folder. You can change width and height. And path of original image and thumbnail image. Better way is to store path in web.config file and access here.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

/// <summary>
/// Summary description for Thumbnail
/// </summary>

public class Thumbnail
private int Width = 100;
private int Height = 100;
string ThumbFolderPath = “~/Contents/Thumb/”;
string OriginalFolderPath = “~/Contents/Images/”;

public Thumbnail()
// TODO: Add constructor logic here

public bool GenerateThumbnail(string fileName)
//Get The Image From File
System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(OriginalFolderPath + fileName));
//Create ITs Thumbnail
System.Drawing.Image ThumbImage = OriginalImage.GetThumbnailImage(Width, Height, null, new System.IntPtr());
//Store It in Thumbnail Folder
ThumbImage.Save(HttpContext.Current.Server.MapPath(ThumbFolderPath + fileName));

return true;
return false;


Rana Faisal Munir

Asp.Net Developer

Relax Solutions


3 Responses to “Create Thumbnail in C#”

  1. 1 Saulo Junior July 30, 2008 at 2:46 am

    Perfect!!! Thanx Rana!

  2. 2 Lawrence July 30, 2008 at 5:01 am

    Hey man, thanks for the code. 😉

  3. 3 Gertrude May 10, 2013 at 2:11 pm

    Thank you for sharing your info. I truly appreciate your efforts and I will be waiting for your further write ups thank you once again.

Leave a Reply

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

You are commenting using your 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: