Multiple image upload:
There are some simple steps to understand this application.
Step 1: Create a new ASP.NET application.
Step 2: Write the following inline code on Default.aspx page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>WebForm1</title>
</head>
<body>
<form id="Form1" method="post" runat="server" style="width: 530px;">
<fieldset>
<legend>Upload Multiple Photos</legend>
<div id="div1" runat="server">
<input type="file" size="65" runat="server" id="FileUpload1">
<input type="file" size="65" runat="server" id="FileUpload2">
<input type="file" size="65" runat="server" id="FileUpload3">
<input type="file" size="65" runat="server" id="FileUpload4">
<input type="file" size="65" runat="server" id="FileUpload5">
</div>
<br />
<div id="div2" runat="server" visible="false">
<input type="file" size="65" runat="server" id="FileUpload6">
<input type="file" size="65" runat="server" id="FileUpload7">
<input type="file" size="65" runat="server" id="FileUpload8">
<input type="file" size="65" runat="server" id="FileUpload9">
<input type="file" size="65" runat="server" id="FileUpload10">
</div>
<br />
<asp:Button ID="Button1" runat="server" Text="Upload" OnClick="Button1_Click" />
<asp:Button ID="ButtonMore" runat="server" Text="Add 10 Photos" OnClick="ButtonMore_Click" />
</fieldset>
<br />
<div id="div5" runat="server" visible="false">
<fieldset>
<legend>Show Photos</legend>
<div id="div3" runat="server">
<asp:Image ID="Image1" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image2" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image3" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image4" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image5" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
</div>
<br />
<div id="div4" runat="server" visible="false">
<asp:Image ID="Image6" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image7" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image8" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image9" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
<asp:Image ID="Image10" runat="server" Height="100" Width="100" ImageUrl="~/Image.gif" />
</div>
</fieldset>
</div>
</form>
</body>
</html>
Step 3: Now add the following namespace on the Default.aspx.cs page
using System.IO;
Step 4: Write the following line of code on the Default.aspx.cs
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.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
div5.Visible = true;
HttpFileCollection uploadFilCol = Request.Files;
for (int i = 0; i < uploadFilCol.Count; i++)
{
HttpPostedFile file = uploadFilCol[i];
string fileExt = Path.GetExtension(file.FileName).ToLower();
string fileName = Path.GetFileName(file.FileName);
if (fileName != string.Empty)
{
try
{
if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
{
file.SaveAs(Server.MapPath("~/Images/") + fileName);
if (i == 0)
{
Image1.ImageUrl = "~/Images/" + fileName;
}
if (i == 1)
{
Image2.ImageUrl = "~/Images/" + fileName;
}
if (i == 2)
{
Image3.ImageUrl = "~/Images/" + fileName;
}
if (i == 3)
{
Image4.ImageUrl = "~/Images/" + fileName;
}
if (i == 4)
{
Image5.ImageUrl = "~/Images/" + fileName;
}
if (i == 5)
{
Image6.ImageUrl = "~/Images/" + fileName;
}
if (i == 6)
{
Image7.ImageUrl = "~/Images/" + fileName;
}
if (i == 7)
{
Image8.ImageUrl = "~/Images/" + fileName;
}
if (i == 8)
{
Image9.ImageUrl = "~/Images/" + fileName;
}
if (i == 9)
{
Image10.ImageUrl = "~/Images/" + fileName;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}
protected void ButtonMore_Click(object sender, EventArgs e)
{
if (ButtonMore.Text == "Only five")
{
div2.Visible = false;
ButtonMore.Text = "Add 10 Photos";
div4.Visible = false;
}
else if (ButtonMore.Text == "Add 10 Photos")
{
div2.Visible = true;
ButtonMore.Text = "Only five";
div4.Visible = true;
}
}
}
Step 5: Now run the application. You will get the following output.
Figure 1:
Step 6: Now click on Browse button and select Images which you want to upload.
Figure 2:
Step7: Now click on the upload button.
Figure 3:
Step 8: And if you want to upload more image then click on 'Add 10 Photos' buttons.
Figure 4:
Step 9: Repeat step 6 and 7.
Step 10: Finally go to download files to understand more about this application.
Multiple Image Upload in ASP.NET
In this article, I am going to discuss how to upload multiple images in ASP.NET simultaneously.


Santosh SharmaPosted Jan 1, 2016, 5:56 AM EST
hi just want an upload button and which open file explorer and user can select multiple images with name in any language. can i do it with asp image uploader
yurekha selvamPosted Oct 6, 2015, 9:39 PM EDT
hi sir, i need to upload the multiple images using forech loop. can you help me plss..
Rajeev KumarPosted Nov 27, 2013, 10:39 PM EST
how we validate this.
vicky patelPosted Mar 14, 2013, 2:55 AM EDT
Nice but i need single image to upload in web page using asp.net
Sameera ObiedPosted Sep 15, 2012, 10:02 AM EDT
Thank you very much
Sameera ObiedPosted Sep 15, 2012, 10:02 AM EDT
Thank you very much
loc buiPosted Apr 23, 2012, 6:56 AM EDT
thanks you very much, ^^
rani sarithaeditedPosted Apr 5, 2012, 12:54 AM EDTEdited Apr 5, 2012, 2:11 AM EDT
thanks a lot purushotham garu...............
volety voletyPosted Apr 26, 2011, 10:23 AM EDT
Hi, Thanks for such a good article and Can you give me the lightbox effect for the uploaded images.
surender bhyanPosted Apr 1, 2011, 2:44 AM EDT
Thanks a lot...keep rocking
Aditya choudharyPosted Mar 25, 2011, 12:26 AM EDT
it's really very useful article. thanks for it sir.
sri gayathriPosted Mar 6, 2011, 9:23 PM EST
ur example is good and plz can u help me with emailid validation just that it should end with only .com exetension but not wid any other....
BatyaPosted Dec 14, 2010, 2:15 AM EST
this is good example to upload multiple images to sql database. Sorry, but i want to know how to upload multiple images in c# windows application, could you help me please! I know how to upload one image, but do not know several images ? plese help me, if you have enough time! Thank you!!!!
JoePosted Nov 11, 2010, 12:58 PM EST
Hi, i have an error message appear. Could not find a part of the path 'C:\Documents and Settings\JoeRichards\My Documents\Visual Studio 2008\Projects\ASP In Progress\TestOleDBImageStore\TestOleDBImageStore\Images\Sunset.jpg'. do you have an idea what it is? thank Joe
Arnel RustemoviceditedPosted Aug 8, 2010, 10:00 AM EDTEdited Aug 8, 2010, 10:01 AM EDT
{"Could not find a part of the path 'C:\\Documents and Settings\\RESUL\\Desktop\\MultipleUploadControl\\Images\\ABCD0019.JPG'."} Please Help me
paraveen kumarPosted Jul 13, 2010, 2:48 AM EDT
very good code, thank u/
ds psPosted Nov 29, 2009, 8:14 PM EST
i like your article.its good one.do u have idea of showing the image (pdf/doc files) saved in sql database ,in new web page?if yes,will u plz share for me?
Purushottam RathorePosted Jun 8, 2009, 7:57 PM EDT
Hi Nalini Download this application and paste in to My Documents\Visual Studio 2005\WebSites or make a virtual directory to run this application.
Former memberPosted May 13, 2009, 8:03 PM EDT
Very nice article,keep it up.