ASP for jquery Ajax fileupload. NET Application

Source: Internet
Author: User

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 ();
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.