Introduction
This article describes how to upload multiple files in ASP.NET Web Forms using the jQuery and Generic Handler. Generally developers use the FileUpload Server control to upload files from the client machine to the server that is rendered as as an INPUT element and set to file and allows you to select the file or multiple files. We can use the jQuery to make an Ajax call to the server and POST the multiple selected files to the Generic Handler instead of a full page postback.
In this article for developing the application, I am using Visual Studio 2013 that has the framework 4.5.1. So, let's get started with the following procedure.
Creating WebForms
Step 1: Open Visual Studio and create the ASP.NET Web Application.
Step 2: Select the WebForms project template to proceed.

Visual Studio automatically creates the project and adds files and folders to the project by default.
Creating WebForm
Step 1: Just right-click on the project and add a new folder named "UploadedFiles".

Step 2: Just right-click on the project and add a new Web Form and replace the body content from the following content:
- <form id="form1" runat="server">
- <h2>ASP.NET</h2>
- <p class="lead">Selcting Multiple Files using jQuery and Generic Handler</p>
- <div class="form-group">
- <div>
- <asp:Label runat="server" AssociatedControlID="MultipleFilesUpload">Select Files</asp:Label>
- <asp:FileUpload ID="MultipleFilesUpload" runat="server" AllowMultiple="true" />
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <asp:Button runat="server" ID="BtnUpload" Text="Upload Files" CssClass="btn btn-default" />
- </div>
- </div>
- </form>
In the code above, I used the AllowMultiple property of FileUpload that is set to true. It is one of the HTML 5 features used in here.
Step 2: Now in the <head> section add the following code:
- <script src="Scripts/jquery-1.10.2.js"></script>
- <link href="Content/bootstrap.css" rel="stylesheet" />
- <link href="Content/Site.css" rel="stylesheet" />
- <script type="text/javascript">
- $(document).ready(function () {
- $("#BtnUpload").click(function (event) {
- var uploadfiles = $("#MultipleFilesUpload").get(0);
- var uploadedfiles = uploadfiles.files;
- var fromdata = new FormData();
- for (var i = 0; i < uploadedfiles.length; i++) {
- fromdata.append(uploadedfiles[i].name, uploadedfiles[i]);
- }
- var choice = {};
- choice.url = "UploadHandler.ashx";
- choice.type = "POST";
- choice.data = fromdata;
- choice.contentType = false;
- choice.processData = false;
- choice.success = function (result) { alert(result); };
- choice.error = function (err) { alert(err.statusText); };
- $.ajax(choice);
- event.preventDefault();
- });
- });
- </script>




Anu VPosted Jul 6, 2016, 6:12 AM
Nice
Sr KarthigaPosted Feb 21, 2016, 11:18 PM
nice one
Sr KarthigaPosted Feb 21, 2016, 11:18 PM
Nice explanation
mona bagherePosted May 10, 2014, 4:02 AM
hello .this code in IE not working.why?