<summary>///speed limit, Resource usage///</summary>//<param name= "_request" >page . Request Object </param>//<param name= "_response" >page.response object </param>//<param name= " _filename "> Download file name </param>//<param name=" _fullpath "> Download path with file name </param>//<param Nam E= "_speed" > bytes allowed to be downloaded per second </param>//<returns> return success </returns> public static bool Response File (HttpRequest _request, HttpResponse _response, String _filename, String _fullpath, Long _speed) {TR y {FileStream myFile = new FileStream (_fullpath, FileMode.Open, FileAccess.Read, FileShare.Read Write); BinaryReader br = new BinaryReader (myFile); try {_response.addheader ("accept-ranges", "bytes"); _response.buffer = false; Long filelength = myfile.length; Long startbytes = 0; int pack = 10240; int sleep = 200; int sleep = (int) Math.floor ((double) (+ * Pack/_speed)) + 1; if (_request.headers["Range"] = null) {_response.statuscode = 206; string[] Range = _request.headers["range"]. Split (new char[] {' = ', '-'}); Startbytes = Convert.toint64 (range[1]); } _response.addheader ("Content-length", (filelength-startbytes). ToString ()); if (startbytes! = 0) {_response.addheader ("Content-range", String. Format ("bytes {0}-{1}/{2}", Startbytes, FileLength-1, filelength)); } _response.addheader ("Connection", "keep-alive"); _response.contenttype = "Application/octet-stream"; _response.addhEader ("Content-disposition", "attachment;filename=" + httputility.urlencode (_filename, System.Text.Encoding.UTF8)) ; Br. Basestream.seek (Startbytes, Seekorigin.begin); int maxCount = (int) Math.floor ((Double) ((filelength-startbytes)/pack) + 1; for (int i = 0; i < MaxCount; i++) {if (_response.isclientconnected) {_response.binarywrite (br. Readbytes (pack)); Thread.Sleep (Sleep); } else {i = MaxCount; }}} catch {return false; } finally {Br. Close (); Myfile.close (); }} catch { return false; } return true; } |