The degree of film processing recently. I read many online examples, mostly PHP, and finally saw luq885 on cnblogs.
For the Asp.net application, he wrote a few examples below, fully satisfying some basic requirements. Because there is only front-end code on its homepage, and there is no back-end Asp.net code, it is inconvenient for everyone to learn. So here, I will release all front-end and back-end code, it is easy for you to view and learn.
<SCRIPT type = "text/JavaScript" Language = "JavaScript">
Function ajaxfileupload ()
{
$ ("# Loading ")
. Ajaxstart (function (){
$ (This). Show ();
})
. Ajaxcomplete (function (){
$ (This). Hide ();
});
$. Ajaxfileupload
(
{
URL: 'doupload. aspx ',
Secureuri: false,
Fileelementid: 'filetupload ',
Datatype: 'json ',
Success: function (data, status)
{
If (typeof (data. Error )! = 'Undefined ')
{
If (data. Error! = '')
{
Alert (data. Error );
} Else
{
Alert (data. msg );
}
}
},
Error: function (data, status, E)
{
Alert (E );
}
}
)
Return false;
}
</SCRIPT>
The backend Asp.net code doupload. aspx references the namespace using system. IO;
And create a file folder in the same directory to install the uploaded files.
If (request. Files. Count> 0)
{
Httppostedfile file = request. Files [0];
String MSG = "";
String error = "";
If (file. contentlength = 0)
Error = "the file length is 0 ";
Else
{
File. saveas (server. mappath ("file") + "//" + path. getfilename (file. filename ));
MSG = "uploaded ";
}
String result = "{error: '" + error + "', MSG: '" + MSG + "'}";
Response. Write (result );
Response. End ();
}