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 ;}}}