求高手帮忙解释这一段代码的意思,看不懂,public void downLoad(string fileName,string path){Response.BufferOutput = false;Response.Clear();Response.AppendHeader("Content-Disposition","attachment; filename=" + Server.UrlEncode(fileName))
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 20:12:13
求高手帮忙解释这一段代码的意思,看不懂,public void downLoad(string fileName,string path){Response.BufferOutput = false;Response.Clear();Response.AppendHeader("Content-Disposition","attachment; filename=" + Server.UrlEncode(fileName))
求高手帮忙解释这一段代码的意思,看不懂,
public void downLoad(string fileName,string path)
{
Response.BufferOutput = false;
Response.Clear();
Response.AppendHeader("Content-Disposition","attachment; filename=" + Server.UrlEncode(fileName));//防止中文名出现乱码
Response.ContentType = "application/octstream";
Response.CacheControl = "Private";
Stream stm = new FileStream(path,FileMode.Open,FileAccess.Read,FileShare.Read);
Response.AppendHeader("Content-length",stm.Length.ToString());
BinaryReader br = new BinaryReader(stm);
byte[] bytes;
for (Int64 x = 0; x < (br.BaseStream.Length / 4096 + 1); x++)
{
bytes = br.ReadBytes(4096);
Response.BinaryWrite(bytes);
System.Threading.Thread.Sleep(5); //休息一下,防止耗用带宽太多.
}
stm.Close();
}
求高手帮忙解释这一段代码的意思,看不懂,public void downLoad(string fileName,string path){Response.BufferOutput = false;Response.Clear();Response.AppendHeader("Content-Disposition","attachment; filename=" + Server.UrlEncode(fileName))
Response.BufferOutput首先这个东东的意思是:是否要当前页面处理完后才发送到浏览器,这里是false,说明将分多次返回页面处理结果
下面的代码意思:读取一个文件到文件流,并分多次返回到浏览器,每5毫秒一次,完成后关闭文件流