One: TransmitFile file download, do not need to open close file, directly into the transport stream
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader ("Content-disposition",
"Attachment;filename=z.zip");
string filename = Server.MapPath ("Download/z.zip");
Response.TransmitFile (filename);
Two:
}
//
Second: WriteFile download file
String fileName = "Asd.txt";//
File name saved by the client
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 ();
Three: Stream mode download
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 a file instead of opening it
Response.AddHeader ("Content-disposition", "attachment; Filename= "+ httputility.urlencode (FileName, System.Text.Encoding.UTF8));
Response.BinaryWrite (bytes);
Response.Flush ();
Response.End ();
Four: WriteFile download their own Baidu to
C # File Download method