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.
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Santosh SharmaPosted Jan 1, 2016, 10:56 AM
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 7, 2015, 1:39 AM
hi sir, i need to upload the multiple images using forech loop. can you help me plss..
Rajeev KumarPosted Nov 28, 2013, 3:39 AM
how we validate this.
vicky patelPosted Mar 14, 2013, 6:55 AM
Nice but i need single image to upload in web page using asp.net
Sameera ObiedPosted Sep 15, 2012, 2:02 PM
Thank you very much
Sameera ObiedPosted Sep 15, 2012, 2:02 PM
Thank you very much
loc buiPosted Apr 23, 2012, 10:56 AM
thanks you very much, ^^
rani sarithaeditedPosted Apr 5, 2012, 4:54 AMEdited Apr 5, 2012, 6:11 AM
thanks a lot purushotham garu...............
volety voletyPosted Apr 26, 2011, 2:23 PM
Hi, Thanks for such a good article and Can you give me the lightbox effect for the uploaded images.
surender bhyanPosted Apr 1, 2011, 6:44 AM
Thanks a lot...keep rocking
Aditya choudharyPosted Mar 25, 2011, 4:26 AM
it's really very useful article. thanks for it sir.
sri gayathriPosted Mar 7, 2011, 2:23 AM
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, 7:15 AM
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, 5:58 PM
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, 2:00 PMEdited Aug 8, 2010, 2:01 PM
{"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, 6:48 AM
very good code, thank u/
ds psPosted Nov 30, 2009, 1:14 AM
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, 11:57 PM
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 14, 2009, 12:03 AM
Very nice article,keep it up.