In this article I will explain with an example, how to upload multiple files using FileUpload Control in ASP.Net 4.5 using C# and VB.Net.
This article makes use of ASP.Net version 4.5.
HTML Markup
The following HTML Markup consists of an ASP.Net FileUpload control, an ASP.Net Button and an ASP.Net Label control.
The FileUpload control has been set with AllowMultiple property to True.
The ASP.Net Button has been assigned with an OnClick event handler.
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="UploadMultipleFiles" />
<hr />
<asp:Label ID="lblSuccess" runat="server" ForeColor ="Green" />
You will need to import the following namespace.
using System.IO;
Imports System.IO
Uploading multiple files with ASP.Net 4.5 FileUpload
When the Upload Button is clicked, following event handler is executed.
Inside this event handler, first a check is performed whether the Folder (Directory) exists. If it does not then, the Folder (Directory) is created.
Next, a loop is executed over the FileUpload PostedFiles property which holds the uploaded files.
Inside the loop, the names of the files are extracted and then the files are stored in Folder (Directory).
Finally, the success message is displayed using the Label control.
protected void UploadMultipleFiles(object sender, EventArgs e)
    string folderPath = Server.MapPath("~/Files/");
    //Check whether Directory (Folder) exists.
    if (!Directory.Exists(folderPath))
        //If Directory (Folder) does not exists. Create it.
    foreach (HttpPostedFile postedFile in FileUpload1.PostedFiles)
        //Save the File to the Directory (Folder).
        postedFile.SaveAs(folderPath + Path.GetFileName(postedFile.FileName));
    //Display the success message.
    lblSuccess.Text = string.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count);
Protected Sub UploadMultipleFiles(sender As Object, e As EventArgs)
    Dim folderPath As String = Server.MapPath("~/Files/")
    'Check whether Directory (Folder) exists.
    If Not Directory.Exists(folderPath) Then
        'If Directory (Folder) does not exists. Create it.
    End If
    ForEach postedFile As HttpPostedFile In FileUpload1.PostedFiles
        'Save the File to the Directory (Folder).
        postedFile.SaveAs(folderPath & Path.GetFileName(postedFile.FileName))
    'Display the success message.
    lblSuccess.Text = String.Format("{0} files have been uploaded successfully.", FileUpload1.PostedFiles.Count)
End Sub
ASP.Net 4.5: Uploading Multiple Files using FileUpload Control
Browser Compatibility

The above code has been tested in the following browsers only in versions that support HTML5.
Internet Explorer  FireFox  Chrome  Safari  Opera 

* All browser logos displayed above are property of their respective owners.


Other available versions