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();