Hui SajidHussa,
Refer below sample.
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#btnUpload").on("click", function () {
var formData = new FormData();
if ($('#File1')[0].files[0] != null) {
formData.append($('#File1')[0].files[0].name, $('#File1')[0].files[0]);
}
if ($('#File2')[0].files[0] != null) {
formData.append($('#File2')[0].files[0].name, $('#File2')[0].files[0]);
}
if ($('#File3')[0].files[0] != null) {
formData.append($('#File3')[0].files[0].name, $('#File3')[0].files[0]);
}
if ($('#File4')[0].files[0] != null) {
formData.append($('#File4')[0].files[0].name, $('#File4')[0].files[0]);
}
$.ajax({
url: 'Handler.ashx',
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
success: function (result) {
}, error: function (r) {
alert(r.d);
}
});
});
});
</script>
<input type="file" id="File1" /><br />
<input type="file" id="File2" /><br />
<input type="file" id="File3" /><br />
<input type="file" id="File4" /><br />
<input type="button" id="btnUpload" value="Upload" />
Handler
C#
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.IO;
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
for (int i = 0; i < context.Request.Files.Count; i++)
{
HttpPostedFile postedFile = context.Request.Files[i];
string folderPath = context.Server.MapPath("~/Uploads/");
string fileName = Path.GetFileName(postedFile.FileName);
postedFile.SaveAs(folderPath + fileName);
}
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
VB.Net
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
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
For i As Integer = 0 To context.Request.Files.Count - 1
Dim postedFile As HttpPostedFile = context.Request.Files(i)
Dim folderPath As String = context.Server.MapPath("~/Uploads/")
Dim fileName As String = Path.GetFileName(postedFile.FileName)
postedFile.SaveAs(folderPath & fileName)
Next
End If
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class