private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
string filepath = Server.MapPath("\\MyAsp\\WebApplication3\\Books\\a.rm");
Response.AddHeader("content-disposition","attachment;filename=" + "a.rm");
Response.ContentType=@"application/octet-stream";
Response.WriteFile(filepath);
Response.End(); }

解决方案 »

  1.   


    不行吗?就算是先读到我的内存也不至于从300M一下到600M ->重起机器才行
      

  2.   

    .net提供的方法一般是先读全部数据到内存中再处理,所以文件大的话不要用WriteFile方法,而是自己去一段一段的读文件并输出。
      

  3.   

    page_load
    {
    FileStream fs=new FileStream("d:\\a.rm",FileMode.Open);
    byte[] buffer=new byte[(int)fs.Length];
    //   fs.Read(buffer,0,(int)fs.Length);
    //   fs.Close ();
    //        // 下载文件
    //   Page.Response.AddHeader( "Content-Type", "application/octet-stream" );
    //   Response.Charset = "GB2312"; 
    //   Response.Buffer=true;
    //   HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(("11.xml")));
    ////   Response.OutputStream.Write(buffer,0,buffer.Length);
    //   Response.OutputStream.BeginWrite(buffer,0,buffer.Length,new AsyncCallback(this.MyCallBack),Response.OutputStream);
    }
     private void MyCallBack(IAsyncResult ar)
      {
       NetworkStream str=(NetworkStream)ar.AsyncState;
        HttpContext.Current.Response.ClearHeaders();
          str.EndWrite(ar);  }
      

  4.   

    尝试一下代码:
    string serverF= Server.MapPath("\\MyAsp\\WebApplication3\\Books\\a.rm");
    Response.Clear();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition","attachment;filename=" + "a.rm");
    FileStream fs = File.OpenRead(serverF);
    byte [] bytes = new Byte[fs.Length];
    fs.Read(bytes,0,(int)fs.Length);
    fs.Close();
    Response.BinaryWrite(bytes);
    Response.End();
      

  5.   

    我试试Oceanson(洋之光)的 看看
      

  6.   

    用循环去read和BinaryWrite,每次只读一部分文件(比如50K),而不是一次全部读出来再BinaryWrite到浏览器。