There are many situations when a user wants to allow a user to upload more than one file, and you're stuck with either adding as many file input elements
This article helps in uploading multiple files simultaneously in ASP.NET. This article uses the HTML File Input control and
Using the code
Using this code doesn't get much simpler, thanks to Microsoft's .NET. The heart of this code is the script which helps to get the FileOpen dialog in ASP.NET.
var file = "";
if(document.getElementById("TextBox1").value == "")
file = document.getElementById("file1").value;
file = document.getElementById("TextBox1").value + "\r\n" +
document.getElementById("TextBox1").value = file ;
To use this code, just run the web application. Once done, it is easy, just click the Add Files button to start uploading the files along with
the details as shown in the
The code for the Add Files button click is shown below:
protected void Button1_Click(object sender, EventArgs e)
if (TextBox1.Text.Length > 0)
DataRow dr = null;
FileInfo fileObj = new FileInfo(TextBox1.Text.Trim());
long size = fileObj.Length / 1024;
loggedUser = "Administrator";
folderPath = System.Web.Hosting.HostingEnvironment.MapPath("~/" + loggedUser);
System.IO.DirectoryInfo dirObj = new DirectoryInfo(folderPath);
fileObj.CopyTo(folderPath + "\\" + fileObj.Name);
catch (Exception ee)
TextBox1.Text = "";
string error = ee.Message.ToString();
Response.Write("<script> window.alert(' File With the " +
"same name already uploaded ')</script>
If you wish to delete the file, then just use the delete option in the
Once all the files to be uploaded are added, you can continue processing the files and upload the files by clicking the Upload Files button.
The processing code for the Upload Files button is left as an exercise to the user.
Points of Interest
This article makes use of the HTML File Input control and
GridView. It is very simple and easy to work around.
Good luck guys!