Copy past below code in .aspx page
<form id="form1" runat="server">
<div>
<asp:Label ID="labelMessage" runat="server" Text="Browse Image:" ForeColor="navy" Width="220"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" />
</div>
<div>
<asp:Label ID="label1" runat="server" Text="Normal Image (Full size): " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="NormalImage" runat="server" />
</div>
<div>
<asp:Label ID="label2" runat="server" Text="Thumbnail Small Image (50x50)px: " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageS" runat="server" />
</div>
<div>
<asp:Label ID="label3" runat="server" Text="Thumbnail Large Image (100x100)px: "
ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageM" runat="server" />
</div>
</form>
Create 1 main folder for images
1. Image
Create 2 sub folders to above "image " folder
1. S (for small images )
2. L (for for big images.
Copy past the below code in .aspx.cs page.
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Upload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(MapPath("~/Image/" + FileUpload1.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/image/") + FileUpload1.FileName);
System.Drawing.Image bmp1 = img1.GetThumbnailImage(50, 50, null, IntPtr.Zero);
bmp1.Save(MapPath("~/thumbnail/S/") + FileUpload1.FileName);
System.Drawing.Image bmp2 = img1.GetThumbnailImage(100, 100, null, IntPtr.Zero);
bmp2.Save(MapPath("~/thumbnail/L/") + FileUpload1.FileName);
NormalImage.ImageUrl = "~/Image/" + FileUpload1.FileName;
ThumbnailImageS.ImageUrl = "~/thumbnail/S/" + FileUpload1.FileName;
ThumbnailImageM.ImageUrl = "~/thumbnail/L/" + FileUpload1.FileName;
}
}
}
<form id="form1" runat="server">
<div>
<asp:Label ID="labelMessage" runat="server" Text="Browse Image:" ForeColor="navy" Width="220"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" />
</div>
<div>
<asp:Label ID="label1" runat="server" Text="Normal Image (Full size): " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="NormalImage" runat="server" />
</div>
<div>
<asp:Label ID="label2" runat="server" Text="Thumbnail Small Image (50x50)px: " ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageS" runat="server" />
</div>
<div>
<asp:Label ID="label3" runat="server" Text="Thumbnail Large Image (100x100)px: "
ForeColor="navy" Width="220"></asp:Label>
<asp:Image ID="ThumbnailImageM" runat="server" />
</div>
</form>
Create 1 main folder for images
1. Image
Create 2 sub folders to above "image " folder
1. S (for small images )
2. L (for for big images.
Copy past the below code in .aspx.cs page.
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Upload_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
FileUpload1.SaveAs(MapPath("~/Image/" + FileUpload1.FileName));
System.Drawing.Image img1 = System.Drawing.Image.FromFile(MapPath("~/image/") + FileUpload1.FileName);
System.Drawing.Image bmp1 = img1.GetThumbnailImage(50, 50, null, IntPtr.Zero);
bmp1.Save(MapPath("~/thumbnail/S/") + FileUpload1.FileName);
System.Drawing.Image bmp2 = img1.GetThumbnailImage(100, 100, null, IntPtr.Zero);
bmp2.Save(MapPath("~/thumbnail/L/") + FileUpload1.FileName);
NormalImage.ImageUrl = "~/Image/" + FileUpload1.FileName;
ThumbnailImageS.ImageUrl = "~/thumbnail/S/" + FileUpload1.FileName;
ThumbnailImageM.ImageUrl = "~/thumbnail/L/" + FileUpload1.FileName;
}
}
}