1.设置请求类型:
context.Response.ContentType = "application/download";
2.设置报文头
string EncodeFileName = HttpUtility.UrlEncode(“1.txt”, System.Text.Encoding.UTF8);
context.Response.AddHeader("Content-Disposition", "attachment;filename=" + EncodeFileName + ";");
3.输出数据流
context.Response.BinaryWrite(System.IO.File.ReadAllBytes(RealFile));//返回文件数据给客户端下载
context.Response.Flush();
context.Response.End();