aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Upload Multiple Files in using Handler File in C#, VB.NET

May 21, 2015

Here I will explain how to upload multiple files using
jQuery in with generic handler (ashx) in c#, or jQuery upload multiple files in using HTML5 “AllowMultiple” property of fileupload in c#,

In previous articles I explained
jQuery call page methods from json, 7 + jQuery multiple fileupload plugin examples, jQuery check file size before upload in, jQuery setInterval() function example, jQuery upload multiple files using uplodify plugin in and many articles relating to jQuery, JavaScript and Now I will explain how to upload multiple files using jQuery with generic handler (ashx) in using c#,

To upload multiple files using jQuery with generic handler (ashx) in first create the new web application and open Default.aspx page and write the following code

<html xmlns="">
<head runat="server">
<title>uploading file using jquery with generic handler ashx</title>
<script src="" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#btnUpload').click(function () {
var fileUpload = $("#FileUpload1").get(0);
var files = fileUpload.files;
var test = new FormData();
for (var i = 0; i < files.length; i++) {
test.append(files[i].name, files[i]);
url: "UploadHandler.ashx",
type: "POST",
contentType: false,
processData: false,
data: test,
// dataType: "json",
success: function (result) {
error: function (err) {
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" /> 
<input type="button" id="btnUpload" value="Upload Files"/>

If you observe fileupload controller we mentioned property called “AllowMultiple” its HTML5 feature and it will allow us to select multiple files at a time. If you observe above jQuery ajax method we mentioned “UploadHandler.ashx” by using this file we will upload files in server side. Now add handler file in your application by following below steps

Right click on your application à select Add New Item à select Generic Handler file à Give a name and click Add button like as shown below

Once you finished adding handler file now add new folder in your application “uploads” that would be like as shown below

Now open UploadHandler.ashx file and write the following code

C# Code

<%@ WebHandler Language="C#" Class="UploadHandler" %>

using System;
using System.Web;
using System.IO;

public class UploadHandler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
if (context.Request.Files.Count > 0)
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
HttpPostedFile file = files[i];
string fname;
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
fname = file.FileName;
fname=Path.Combine(context.Server.MapPath("~/uploads/"), fname);
context.Response.ContentType = "text/plain";
context.Response.Write("File Uploaded Successfully!");
public bool IsReusable {
get {
return false;


<%@ WebHandler Language="VB" Class="Handler" %>

Imports System.Web
Imports System.IO

Public Class Handler : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
If context.Request.Files.Count > 0 Then
Dim files As HttpFileCollection = context.Request.Files
For i As Integer = 0 To files.Count - 1
Dim file As HttpPostedFile = files(i)
Dim fname As String
If HttpContext.Current.Request.Browser.Browser.ToUpper() = "IE" OrElse HttpContext.Current.Request.Browser.Browser.ToUpper() = "INTERNETEXPLORER" Then
Dim testfiles As String() = file.FileName.Split(New Char() {"\"c})
fname = testfiles(testfiles.Length - 1)
fname = file.FileName
End If
fname = Path.Combine(context.Server.MapPath("~/uploads/"), fname)
End If
context.Response.ContentType = "text/plain"
context.Response.Write("File Uploaded Successfully!")
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Return False
End Get
End Property
End Class

Now run your application that will allow you to upload files in upload folder using handler files.


jQuery Upload Multiple Files in using Handler File in C#, VB.NET
Download Sample Attached

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Unknown said...

Hi Suresh Sir,
Your post helped me a lot. Thanks for sharing. Now a days I am stuck at a point. I need realtime file upload progress i.e. FileSize and remaining size to be uploaded, remaining time, percent completed along with a progress bar. Kindly help as I am working on it from past 3 days. I need to upload very huge file on to the server whatever file extension it has.

Kindly help will be so grateful of you.

Anonymous said...

Hi sir if i select ed one by one then it uploadeed several times

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.