Simple processing of ASP. NET large File Upload

Source: Internet
Author: User

In the process of ASP. File uploads often use their own FileUpload controls, but as everyone knows, the limitations of this control are huge, and the biggest problem is that developers are particularly headache when uploading large files, and Upload can not be convenient to do multi-threaded control and upload the progress of the display. Here we recommend an easy-to-use upload component to quickly and easily solve the large file upload problem in ASP.

First, we need this component named Ranupload (included in the example below), the two DLL files are added to the project's reference Central, and the XML file is copied in the Bin folder of the project, that is, the last three files are in the Bin folder.

Next, the upload control or the FileUpload control that comes with ASP. Add a label next to the FileUpload control:

C # code
    1. <radu:radprogressmanager id="Radprogressmanager1" width="100%" runat="server"/>
    2. <radu:radprogressarea id="progressArea1" width="100%" runat="Server" ></radu:radprogressarea >

and add the following code at the beginning of the foreground page aspx file:

C # code
  1. <form id="Form1" runat= "Server" >
  2. <div>
  3. <radu:radprogressmanager id="Radprogressmanager1" width="100%" runat="server"/>
  4. <radu:radprogressarea id="progressArea1" width="100%" runat= "Server" >
  5. </radU:RadProgressArea>
  6. <asp:fileupload runat="Server" id="FileUpload"/>
  7. &nbsp;&nbsp;&nbsp;
  8. <asp:button runat="Server" id="fileupladbtn" text= "upload " onclick= "Fileupladbtn_onclick"/>
  9. </div>
  10. </form>

Of course, the following statements cannot be forgotten in the <system.web> tag of the configuration file:

C # code
  1. <!--file Upload control configuration-
  2. "3600" maxrequestlength="2097151" >
  3. <add name="Raduploadmodule" type="Telerik.WebControls.RadUploadHttpModule, Radupload.net2"/>
  4. <add verb="*" path="Telerik.RadUploadProgressHandler.aspx" type=" Telerik.WebControls.RadUploadProgressHandler, Radupload.net2 "></add>

Here is the background file upload operation

C # code
  1. protected void Fileupladbtn_onclick (object sender, EventArgs e)
  2. {
  3. if (raduploadcontext.current = = null) { return;}
  4. if (RadUploadContext.Current.UploadedFiles.Count <= 0)
  5. {
  6. This . Page.ClientScript.RegisterStartupScript (This. Page.gettype (), "MsgBox", "<script>alert (' Please select Upload file!  ') </script> ");
  7. return;
  8. }
  9. if (raduploadcontext.current.uploadedfiles[0]. ContentLength >= 2147483647)
  10. {
  11. This . Page.ClientScript.RegisterStartupScript (This. Page.gettype (), "MsgBox", "<script>alert (' uploaded files must not exceed 2GB!")  ') </script> ");
  12. return;
  13. }
  14. UploadedFile file = Raduploadcontext.current.uploadedfiles[0];
  15. string fileName = Path.getfilename (file.  FileName);
  16. string virtualpath = System.IO.Path.Combine ("~/files", fileName);
  17. string savepath = this .  MapPath (virtualpath);
  18. File.   SaveAs (Savepath, true);
  19. }

    • bigfileupload.rar  (236.2 KB)

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.