Using system;using system.data;using system.configuration;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 _default:system.web.ui.page{protected void Page_Load (object sender, EventArgs e) {}//transmitfile Real Download now protected void Button1_Click (object sender, EventArgs e) {Response.ContentType = "application/x-zip-compressed"; Response.AddHeader ("Content-disposition", "Attachment;filename=z.zip"); string filename = Server.MapPath ("DownLoad/ Z.zip "); Response.TransmitFile (filename);} WriteFile implementation download protected void button2_click (object sender, EventArgs e) {string filename = "Asd.txt";//client-saved file name string Filepath=server.mappath ("Download/aaa.txt");//path FileInfo FileInfo = new FileInfo (FilePath); Response.Clear (); Response.clearcontent (); Response.ClearHeaders (); Response.AddHeader ("Content-disposition", "attachment;filename=" + filename); Response.addhEader ("Content-length", fileInfo.Length.ToString ()); Response.AddHeader ("content-transfer-encoding", "binary"); Response.ContentType = "Application/octet-stream"; response.contentencoding = System.Text.Encoding.GetEncoding ("gb2312"); Response.WriteFile (Fileinfo.fullname); Response.Flush (); Response.End ();} WriteFile chunked download protected void button3_click (object sender, EventArgs e) {string filename = "Aaa.txt";//client-saved file name string FilePath = Server.MapPath ("Download/aaa.txt");//path System.IO.FileInfo FileInfo = new System.IO.FileInfo (FilePath); if (fileinfo.exists = = true) {Const LONG ChunkSize = 102400;//100k reads the file every time, only 100K is read, which can relieve the pressure on the server byte[] buffer = new Byte[chun Ksize]; Response.Clear (); System.IO.FileStream IStream = System.IO.File.OpenRead (FilePath); Long datalengthtoread = istream.length;// Gets the total size of the downloaded file Response.ContentType = "Application/octet-stream"; Response.AddHeader ("Content-disposition", "attachment; Filename= "+ httputility.urlencode (fileName)); while (Datalengthtoread > 0 && Response.isclientconnected) {int lengthread = istream.read (buffer, 0, Convert.ToInt32 (ChunkSize));// Read size Response.OutputStream.Write (buffer, 0, lengthread); Response.Flush ();d atalengthtoread = Datalengthtoread-lengthread;} Response.close ();}} Stream download protected void Button4_Click (object sender, EventArgs e) {string filename = "Aaa.txt";//client-saved file name string FilePath = Server.MapPath ("Download/aaa.txt");///path//download file as character stream FileStream fs = new FileStream (FilePath, FileMode.Open); byte[] bytes = new byte[(int) fs. Length];fs. Read (bytes, 0, bytes. Length); fs. Close (); Response.ContentType = "Application/octet-stream";//notifies the browser to download the file instead of opening Response.AddHeader ("Content-disposition", " Attachment Filename= "+ httputility.urlencode (FileName, System.Text.Encoding.UTF8)); Response.BinaryWrite (bytes); Response.Flush (); Response.End (); }}