Asp.net resumable upload,

Source: Internet
Author: User
Tags asp net

Asp.net resumable upload,

Using System; using System. data; using System. configuration; using System. collections; using System. web; using System. web. security; using System. web. UI; using System. web. UI. webControls; using System. web. UI. webControls. webParts; using System. web. UI. htmlControls; using System. IO; public partial class DFile: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {} protected void LinBtnDFile_Click (object sender, EventArgs e) {// create a bit array byte [] buffer = new Byte [10240]; // specify the path of the file to be downloaded. string filePath = @ "D: \ .rar"; // or the file name contains the extension string fileName = Path. getFileName (filePath); Stream fileStream = null; try {// open the file fileStream = new FileStream (filePath, FileMode. open, FileAccess. read, FileShare. read); Response. clear (); // obtain the file size long fileSize = fileStream. length; long sum = 0; if (Request. Headers ["Range"]! = Null) {Response. StatusCode = 206; // an integer that indicates the HTTP output status returned to the client. The default value is 200. Sum = long. parse (Request. headers ["Range"]. replace ("bytes = ",""). replace ("-", "");} if (sum! = 0) {Response. addHeader ("Content-Range", "bytes" + sum. toString () + "-" + (long) (fileSize )). toString () + "/" + fileSize. toString ();} // get some http header information Response. addHeader ("Content-Length", (long) (fileSize-sum )). toString (); Response. contentType = "application/octet-stream"; // obtain the file source Response. addHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. urlEncode (Request. contentEncodin G. getBytes (fileName); // Response. flush (); fileStream. position = sum; // set the current stream Position fileSize = fileSize-sum; // when the file size is greater than 0, it enters the loop while (fileSize> 0) {// determine whether the client is still connected to the server if (Response. isClientConnected) {// obtain the total number of bytes in the buffer. int length = fileStream. read (buffer, 0, 10240); // write data Response. outputStream. write (buffer, 0, length); // sends the buffer output to the client Response. flush (); buffer = new Byte [10240]; fileSize = fileSiz E-length;} else {// exit loop fileSize =-1 ;}} catch (Exception ex) {Response. write ("Error:" + ex. message);} finally {if (fileStream! = Null) {// Close the file fileStream. Close () ;}response. End ();}}}

  


A piece of aspnet breakpoint resume code

Qq: 652346044

Asp net http resumable upload full version Program

Baidu searches for "C # resumable upload", hoping that the search results will help you.
 

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.