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
- <radu:radprogressmanager id="Radprogressmanager1" width="100%" runat="server"/>
- <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
- <form id="Form1" runat= "Server" >
- <div>
- <radu:radprogressmanager id="Radprogressmanager1" width="100%" runat="server"/>
- <radu:radprogressarea id="progressArea1" width="100%" runat= "Server" >
- </radU:RadProgressArea>
- <asp:fileupload runat="Server" id="FileUpload"/>
-
- <asp:button runat="Server" id="fileupladbtn" text= "upload " onclick= "Fileupladbtn_onclick"/>
- </div>
- </form>
Of course, the following statements cannot be forgotten in the <system.web> tag of the configuration file:
C # code
- <!--file Upload control configuration-
- "3600" maxrequestlength="2097151" >
- <add name="Raduploadmodule" type="Telerik.WebControls.RadUploadHttpModule, Radupload.net2"/>
- <add verb="*" path="Telerik.RadUploadProgressHandler.aspx" type=" Telerik.WebControls.RadUploadProgressHandler, Radupload.net2 "></add>
Here is the background file upload operation
C # code
- protected void Fileupladbtn_onclick (object sender, EventArgs e)
- {
- if (raduploadcontext.current = = null) { return;}
- if (RadUploadContext.Current.UploadedFiles.Count <= 0)
- {
- This . Page.ClientScript.RegisterStartupScript (This. Page.gettype (), "MsgBox", "<script>alert (' Please select Upload file! ') </script> ");
- return;
- }
- if (raduploadcontext.current.uploadedfiles[0]. ContentLength >= 2147483647)
- {
- This . Page.ClientScript.RegisterStartupScript (This. Page.gettype (), "MsgBox", "<script>alert (' uploaded files must not exceed 2GB!") ') </script> ");
- return;
- }
- UploadedFile file = Raduploadcontext.current.uploadedfiles[0];
- string fileName = Path.getfilename (file. FileName);
- string virtualpath = System.IO.Path.Combine ("~/files", fileName);
- string savepath = this . MapPath (virtualpath);
- File. SaveAs (Savepath, true);
- }
- bigfileupload.rar (236.2 KB)