1 /// <summary>2 ///Download File TransmitFile3 /// </summary>4 /// <param name= "FilePath" ></param>5 Public Static voidDownloadFile (stringFilePath)6 {7 stringfilename =HttpContext.Current.Server.MapPath (filePath);8 varResponse =HttpContext.Current.Response;9Response. ContentType ="application/x-zip-compressed";TenResponse. AddHeader ("content-disposition","attachment;filename="+path.getfilename (filename)); One Response. TransmitFile (filename); A } - - /// <summary> the ///Download Large Files - /// </summary> - /// <param name= "FilePath" ></param> - Public Static voidDownloadbigfile (stringFilePath) + { -FilePath = HttpContext.Current.Server.MapPath (FilePath);//Path + stringFileName = Path.getfilename (FilePath);//file name saved by the client A varResponse =HttpContext.Current.Response; atSystem.IO.FileInfo FileInfo =NewSystem.IO.FileInfo (filePath); - if(Fileinfo.exists = =true) - { - Const LongChunkSize =102400;//100K Read the file every time, only read 100K, this can alleviate the pressure of the server - - byte[] buffer =New byte[ChunkSize]; in - Response. Clear (); toSystem.IO.FileStream IStream =System.IO.File.OpenRead (filePath); + LongDatalengthtoread = Istream.length;//get the total size of the downloaded file -Response. ContentType ="Application/octet-stream"; theResponse. AddHeader ("content-disposition","attachment; Filename="+Httputility.urlencode (FileName)); * while(Datalengthtoread >0&&Response. isclientconnected) $ {Panax Notoginseng //Read size Response.OutputStream.Write (buffer, 0, lengthread); - intLengthread = istream.read (buffer,0, Convert.ToInt32 (ChunkSize)); the Response. Flush (); +Datalengthtoread = Datalengthtoread-Lengthread; A } the + Response. Close (); - } $ } $ - /// <summary> - ///Stream mode Download the /// </summary> - /// <param name= "FilePath" ></param>Wuyi Public Static voidDownloadfilestream (stringFilePath) the { -FilePath = HttpContext.Current.Server.MapPath (FilePath);//Path Wu stringFileName = Path.getfilename (FilePath);//file name saved by the client - varResponse =HttpContext.Current.Response; AboutFileStream fs =NewFileStream (FilePath, FileMode.Open); $ - byte[] bytes =New byte[(int) fs. Length]; Fs. Read (Bytes,0, Bytes. Length); - - FS. Close (); AResponse. ContentType ="Application/octet-stream"; + //notifies the browser to download a file instead of opening it theResponse. AddHeader ("content-disposition","attachment; Filename="+Httputility.urlencode (FileName, System.Text.Encoding.UTF8)); - Response. BinaryWrite (bytes); $ Response. Flush (); the Response. End (); the } the the /// <summary> - ///Download the text as a file in /// </summary> the /// <param name= "text" ></param> the /// <param name= "FileName" ></param> About Public Static voidDownloadtext (stringText,stringfileName) the { the byte[] bytes =Encoding.Default.GetBytes (text); the varResponse =HttpContext.Current.Response; +Response. ContentType ="Application/octet-stream"; - //notifies the browser to download a file instead of opening it theResponse. AddHeader ("content-disposition","attachment; Filename="+Httputility.urlencode (FileName, System.Text.Encoding.UTF8));Bayi Response. BinaryWrite (bytes); the Response. Flush (); the Response. End (); -}