PRB: Response.WriteFile Cannot Download a Large File解决办法
http://support.microsoft.com/default.aspx?scid=kb;en-us;812406

解决方案 »

  1.   

    还是不成啊。我想要让media player能播放
    我用response.writefile出来的文件。怎么做啊?
    用你给我的方法都是下载后才播放的啊?
      

  2.   

    Response.WriteFile似乎会把文件所有内容加载到内存后才输出
    其实还是会有响应的,我试过5xxMB的ISO...后来像孟子写的那样输出
    问题大概解决了,响应很快,也可以下载
    不过IIS占用内存直接增长30M+...
      

  3.   

    但是用windows meidia player 播放。
    播放器是全部下载后才播放的。不是缓存播放的?
    用resposne.writefile可以实现缓存播放,但是文件大了就不行了。
      

  4.   

    // Identify the file to download including its path.
    string filepath = DownloadFileName; // Identify the file name.
    string filename = System.IO.Path.GetFileName(filepath); Response.Clear(); // Specify the Type of the downloadable file.
    Response.ContentType = "application/octet-stream"; // Set the Default file name in the FileDownload dialog box.
    Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); Response.Flush(); // Download the file.
    Response.WriteFile(filepath);这种方法没有效果。不好使。
    还是打不开
      

  5.   

    你这么做还不是一样?? System.IO.Stream iStream = null; // Buffer to read 10K bytes in chunk:
    byte[] buffer = new Byte[10000]; // Length of the file:
    int length; // Total bytes to read:
    long dataToRead; // Identify the file to download including its path.
    string filepath  = "DownloadFileName"; // Identify the file name.
    string  filename  = System.IO.Path.GetFileName(filepath); try
    {
    // Open the file.
    iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open, 
    System.IO.FileAccess.Read,System.IO.FileShare.Read);
    // Total bytes to read:
    dataToRead = iStream.Length; Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + filename); // Read the bytes.
       while (dataToRead > 0)
    {
    // Verify that the client is connected.
    if (Response.IsClientConnected) 
    {
    // Read the data in buffer.
    length = iStream.Read(buffer, 0, 10000); // Write the data to the current output stream.
    Response.OutputStream.Write(buffer, 0, length); // Flush the data to the HTML output.
    Response.Flush(); buffer= new Byte[10000];
    dataToRead = dataToRead - length;
    }
    else
    {
    //prevent infinite loop if user disconnects
    dataToRead = -1;
    }
    }
    }
    catch (Exception ex) 
    {
    // Trap the error, if any.
    Response.Write("Error : " + ex.Message);
    }
    finally
    {
    if (iStream != null) 
    {
    //Close the file.
    iStream.Close();
    }
    }
      

  6.   

    这种方式确实好使。
    但是用media player播放的话。要等好久,需要把文件全部下载后才能播放。
      

  7.   

    怎么才能解决啊???
    是不是应该改一下MIME类型啊?
    Response.ContentType = "application/octet-stream";