public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
byte[] bytes = File.ReadAllBytes("D:\toClient.xls");//toClient.xls 大小为20M
Response.BinaryWrite(bytes);
}
}
运行后直接报:System.OutOfMemoryException
一般是这么写:
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(downloadName, System.Text.Encoding.UTF8));
Response.WriteFile("D:\toClient.xls");
Response.Flush();
Response.End();
不要直接Response.BinaryWrite(bytes);
每次读取一个 byte[]
然后Response.Flush();
可以分析一下原因吗?