Académique Documents
Professionnel Documents
Culture Documents
Net:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>uploading file using jquery with generic handler ashx</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"
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]);
}
$.ajax({
url: "UploadHandler.ashx",
type: "POST",
contentType: false,
processData: false,
data: test,
// dataType: "json",
success: function (result) {
alert(result);
},
error: function (err) {
alert(err.statusText);
}
});
});
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="file" id="FileUpload1" />
<input type="button" id="btnUpload" value="Upload Files"/>
</div>
</form>
</body>
</html>
C#:
using System;
using System.Web;
using System.IO;
fname=Path.Combine(context.Server.MapPath("~/uploads/"),
fname);
file.SaveAs(fname);
}
}
context.Response.ContentType = "text/plain";
context.Response.Write("File Uploaded Successfully!");
}
public bool IsReusable {
get {
return false;
}
}
}
Vb.net:
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