using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
public partial class _Default :
{
protected void Page_Load(object sender, EventArgs e)
{
}
//TransmitFile implementation download
protected void Button1_Click(object sender, EventArgs e)
{
= "application/x-zip-compressed";
("Content-Disposition", "attachment;filename=");
string filename = ("DownLoad/");
(filename);
}
//WriteFile implementation download
protected void Button2_Click(object sender, EventArgs e)
{
string fileName ="";//The file name saved by the client
string filePath=("DownLoad/");//Path
FileInfo fileInfo = new FileInfo(filePath);
();
();
();
("Content-Disposition", "attachment;filename=" + fileName);
("Content-Length", ());
("Content-Transfer-Encoding", "binary");
= "application/octet-stream";
= ("gb2312");
();
();
();
}
//WriteFile chunked download
protected void Button3_Click(object sender, EventArgs e)
{
string fileName = "";//The file name saved by the client
string filePath = ("DownLoad/");//Path
fileInfo = new (filePath);
if ( == true)
{
const long ChunkSize = 102400;//100K Each time you read the file, only 100K is read, which can relieve the pressure on the server.
byte[] buffer = new byte[ChunkSize];
();
iStream = (filePath);
long dataLengthToRead = ;//Get the total size of the downloaded file
= "application/octet-stream";
("Content-Disposition", "attachment; filename=" + (fileName));
while (dataLengthToRead > 0 && )
{
int lengthRead = (buffer, 0, Convert.ToInt32(ChunkSize));//Read size
(buffer, 0, lengthRead);
();
dataLengthToRead = dataLengthToRead - lengthRead;
}
();
}
}
//Download streaming method
protected void Button4_Click(object sender, EventArgs e)
{
string fileName = "";//The file name saved by the client
string filePath = ("DownLoad/");//Path
//Download the file as a character stream
FileStream fs = new FileStream(filePath, );
byte[] bytes = new byte[(int)];
(bytes, 0, );
();
= "application/octet-stream";
//Notify the browser to download the file instead of opening it
("Content-Disposition", "attachment; filename=" + (fileName, .UTF8));
(bytes);
();
();
}
}