Asp. Net large file upload
Recently, asp.net is used for uploading. Because asp.net has a fileupload upload control, but the file size uploaded by this control is limited, it cannot meet the requirement of www.2cto.com.
Baidu, many people encounter asp.net's confusion about uploading ultra-large files. The occasional search found that csdn's buddy mentioned how to implement this ultra-large file, RadUpload. net2.dll also provides this dynamic library for uploading and processing large files. As a result, I downloaded the file and looked at it. The effect was good. It not only supported fast uploading of files with a MB quarrel, but also supported multi-threaded uploading of files.
The controls used to view the source code are also the fileupload control, but the processing process calls RadUpload. Net2.dll.
The uploaded file is stored in the upload folder under bin, and the uploaded file can be renamed.
1. Create An aspx page.
2. Create <asp: FileUpload ID = "FileUpload1" runat = "server"/>.
3. Create <asp: Button ID = "Button3" runat = "server" Text = "Upload" OnClick = "button#click"/>
4. Upload the dynamic library processing process that calls net2.dll in the code.
5. If you create multiple upload files, you can write more <asp: FileUpload ID = "FileUpload1" runat = "server"/>.
6. Click the upload button to perform the processing.
The procedure is as follows:
Foreach (UploadedFile file in RadUploadContext. Current. UploadedFiles)
{
String Path = Server. MapPath (@"~ /Uploads ");
// If the path does not exist, create
If (System. IO. Directory. Exists (Path) = false)
{
System. IO. Directory. CreateDirectory (Path );
}
// Combined path, file. GetName () to get the file name
String oldfilename = file. GetName (). ToString ();
// If you rename the uploaded file and name it according to the guid, release the following two lines of code:
// String fileType = oldfilename. Substring (oldfilename. LastIndexOf ("."));
// String newfilename = Guid. NewGuid (). ToString ("N") + fileType;
// Path = Path + "/" + file. GetName (). ToString ();
Path = Path + "/" + oldfilename;
// Save
File. SaveAs (Path, true );
String newurl = @"~ /Uploads/"+ oldfilename;
}