private void Button1_Click(object sender, System.EventArgs e)
{
System.IO.FileStream r = new System.IO.FileStream("e:/后缀.txt", System.IO.FileMode.Open);
Response.Buffer = false;
Response.AddHeader("Connection", "Keep-Alive");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.IO.Path.GetFileName("e:/后缀.txt"));
Response.AddHeader("Content-Length", r.Length.ToString());
while ((true))
{
byte[] Buffer = new byte[1024];
Int64 leng;
leng = r.Read(Buffer, 0, 1024);
if (leng == 0)
{
goto exitWhileStatement0;
}
if ((leng == 1024))
{
Response.BinaryWrite(Buffer);
}
else
{
byte[] b = new byte[leng];
Int64 i;
for (i = 0; i <= leng; i++)
{
b[i] = Buffer[i];
}
Response.BinaryWrite(b);
}
}
exitWhileStatement0: ;
r.Close();
File.Delete("e:/后缀.txt");
}
{
System.IO.FileStream r = new System.IO.FileStream("e:/后缀.txt", System.IO.FileMode.Open);
Response.Buffer = false;
Response.AddHeader("Connection", "Keep-Alive");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.IO.Path.GetFileName("e:/后缀.txt"));
Response.AddHeader("Content-Length", r.Length.ToString());
while ((true))
{
byte[] Buffer = new byte[1024];
Int64 leng;
leng = r.Read(Buffer, 0, 1024);
if (leng == 0)
{
goto exitWhileStatement0;
}
if ((leng == 1024))
{
Response.BinaryWrite(Buffer);
}
else
{
byte[] b = new byte[leng];
Int64 i;
for (i = 0; i <= leng; i++)
{
b[i] = Buffer[i];
}
Response.BinaryWrite(b);
}
}
exitWhileStatement0: ;
r.Close();
File.Delete("e:/后缀.txt");
}
注意缓冲数组的分配问题
开数组都开这么小