Uploadify+asp.net (C #) bulk upload large file instance source code

Source: Internet
Author: User
Tags httpcontext json save file

Recent project requirements to bulk upload large files, the project is developed with ASP.net (C #), Uploadify upload components personally think very good, support asp.net, PHP, etc., this article we use uploadify to achieve bulk upload large files.


Effect Chart:


Front-end Code with comment Description:


Enable bulk upload:

javascript:$ (' #uploadify '). Uploadify (' upload ', ' * '): Enable bulk upload.

About large file uploads

In the debug upload process, found large files (greater than 20M) on the 500 error, server configuration can be uploaded 500M files. I was reminded that it should be the webconfig of the request content size limit problem. You should follow the following settings:

Sets the size of the request data.

<system.web>
<compilation debug= "true" targetframework= "4.0"/>
<!--set up a large file request-->
& Lt;httpruntime maxrequestlength= "1073741824" executiontimeout= "3600"/>
</system.web>


The server-side code is as follows:

Public void processrequest (httpcontext context) {    context.
response.contenttype =  "Text/plain";     //receive the uploaded file     httppostedfile file = context.
request.files["Filedata"];     //other parameter     //string somekey = context.
request["Somekey"];     //string other = context.
request["Someotherkey"];     //get the save path to the file     string uploadpath =    
     httpcontext.current.server.mappath ("uploadimages"  +  "\");     //to determine whether the uploaded file is empty     if  (file != null)      {        if  (! Directory.Exists (Uploadpath))         {              directory.createdirectory (Uploadpath); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP}         //Save file          file. SaveAs (uploadpath + datetime.now.tostring ("Yyyymmddhhmmsss")  + file. Filename.substring (file. Filename.lastindexof (".")
 - 1));
        responsemodel rm = new responsemodel ();         rm.
id = 1;
        rm.state = 0;         rm.
msg =  "Success";         context. Response.Write (Newtonsoft.Json.JsonConvert.SerializeObject (RM));//is passed to the foreground of data           else     {        context. Response.Write ("0");  //to the front desk datA    &nbsp}} public class responsemodel {    public int  id { get; set; }     public int state { get;  set; }     public string msg { get; set;&nbsp}}


The returned objects after the successful upload can be serialized using JSON. It is then returned to the client invocation. It is advisable to convert the returned JSON string to a JSON object at the time of the client invocation, which is easy to use.

How to handle the data returned by the upload result:

var obj = (new Function ("return" + data));//data for the returned JSON string


Related Article

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.