Click here to Skip to main content
15,900,724 members

Comments by leexb (Top 2 by date)

leexb 12-Oct-13 5:33am View    
aspx page:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>

<script type="text/javascript">
function upload() {
var fileUpload = $("#file").get(0);
var files = fileUpload.files;

var data = new FormData();
for (var i = 0; i < files.length; i++) {
data.append(files[i].name, files[i]);
}
$.ajax({
dataType: 'json',
type: 'POST',
processData: false,
contentType: false,
url: 'UploadFile.ashx',
data: data,
success: function (response) {
alert("posted");
}
});
}
</script>
</head>
<body>
<form id="form" action="" runat="server" enctype="multipart/form-data">
<asp:fileupload runat="server" id="file" onchange="upload();" />
</form>
</body>
</html>

UploadFile.ashx:

public class UploadFile : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
int count = context.Request.Files.Count;
}

public bool IsReusable
{
get
{
return false;
}
}
}
leexb 12-Oct-13 5:17am View    
i try to run your code ,still the same error.
context.Request.Files.count=0 in AjaxUpload.ashx file