C # HTTP resumable upload

Source: Internet
Author: User

 

Using system; using system. collections. generic; using system. LINQ; using system. text; using system. io; using system. net; namespace xcdownloadfile {public class downloadfile {///// File Download Method ///// file storage path and file name /// return the Server File Name // public bool deownloadfile (string strfilename, string file) {bool flag = false; // open the last downloaded file long sposition = 0; // instantiate the stream object filestream fstream; // determine whether the folder to be downloaded exists if (file. exists (strfilename) {// open the file to be downloaded fstream = file. openwrite (strfilename); // get the downloaded length sposition = fstream. length; fstream. seek (sposition, seekorigin. current);} else {// create a file fstream = new filestream (strfilename, filemode. create); sposition = 0;} Try {// open the network connection httpwebrequest myrequest = (httpwebrequest) httpwebrequest. create ("http://www.newxing.com/download/" + file); If (sposition> 0) myrequest. addrange (INT) sposition); // sets the range value // sends a request to the server to obtain the server's response data stream mystream = myrequest. getresponse (). getresponsestream (); // defines a byte Data byte [] btcontent = new byte [512]; int intsize = 0; intsize = mystream. read (BT content, 0,512); While (intsize> 0) {fstream. write (btcontent, 0, intsize); intsize = mystream. read (btcontent, 0,512);} // close stream fstream. close (); mystream. close (); flag = true; // return true download succeeded} catch (exception) {fstream. close (); flag = false; // return false download Failed} return flag ;}}}

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.