Asp.net uses the new features of H5 to Implement Asynchronous upload. New Features of h5
###Index.html
<! DOCTYPE html>
### Index. js
Function formDataUpload () {// You can select multiple files at a time. var fileUpload = document. getElementById ("FileToUpload "). files; if (fileUpload. length = 0) {alert ("select a file and upload it again"); return;} // new html5 feature var formdata = new FormData (); // Add the uploaded data for (var I = 0; I <fileUpload. length; I ++) {formdata. append ('files', fileUpload [I]);} // use javascript native ajax var xmlHttp = new XMLHttpRequest (); xmlHttp. open ("post", 'handler. ashx? Method = formDataUpload '); xmlHttp. onreadystatechange = function () {if (xmlHttp. readyState = 4 & xmlHttp. status = 200) {alert ("uploaded successfully") ;}} xmlHttp. send (formdata );}
### Handler. ashx
<% @ WebHandler Language = "C #" Class = "Handler" %> using System; using System. web; public class Handler: IHttpHandler {public void ProcessRequest (HttpContext context) {formDataUpload (context);} public static void formDataUpload (HttpContext context) {// obtain the file HttpFileCollection files = context submitted by the client. request. files; string msg = string. empty; string error = string. empty; int fileM = 0; if (files. count> 0) {for (int I = 0; I <files. count; I ++) {; String path = @ "D: \" + files [I]. fileName; files [I]. saveAs (path); fileM + = files [I]. contentLength;} msg = "uploaded successfully, total file size:" + fileM; string res = "{error: '" + error + "', msg: '"+ msg +"'} "; context. response. write (res); context. response. end () ;}} public bool IsReusable {get {return false ;}}}
The above example of asp.net using the new H5 feature to Implement Asynchronous upload is all the content shared by Alibaba Cloud. I hope to give you a reference, and I hope you can provide more support to the customer's house.