2010-07-01 144 views
0

我在同一位置有兩個文件,但是大的文件即將完成下載時會出現錯誤(包括IE和Firefox) 。下載25MB文件時出現問題 - 無問題下載8MB文件(ASP.NET)

我使用下面的代碼:

public static void DownloadZipFile (string filename, bool notifyMe) 
{ 
    HttpContext context = HttpContext.Current; 
    HttpServerUtility server = context.Server; 
    bool ok = false; 
    try 
    { 
     string file = string.Format ("~/contents/licensing/members/downloads/{0}", filename); 
     string server_file = server.MapPath (file); 

     HttpResponse response = context.Response; 
     //response.BufferOutput = false; 
     response.ContentType = "application/zip"; 
     string value = string.Format ("attachment; filename={0}", filename); 
     response.AppendHeader ("Content-Disposition", value); 
     FileInfo f = new FileInfo (server_file); 
     long size = f.Length; 
     response.TransmitFile (server_file, 0, size); 
     response.Flush(); 
     ok = true; 
     response.End(); 
    } 
    catch (Exception ex) 
    { 
     Utilities.Log (ex); 
    } 
    finally 
    { 
     if (ok && notifyMe) 
      NotifyDownload (filename); 
    } 
} 

任何想法?

+0

您收到了什麼錯誤? – Garett 2010-07-01 04:05:12

+2

獲得大小後,添加'response.AddHeader(「Content-Length」,size.ToString());'我有類似的問題想客戶想要「在一個頁面上的所有記錄」,並且有70,000條記錄一個沒有任何延遲寫入的應用程序。 :(iirc,cap是8MB。 – 2010-07-01 04:07:44

+0

Jim:+1,因爲你提出的解決了我所遇到的問題。現在我可以下載25MB的文件。如果你願意,可以發表評論作爲答案。我知道這是b ...但是我必須選擇一個答案,或者不要,不管怎麼說,沒關係,照你所希望的那樣做,謝謝 – ileon 2010-07-01 05:01:00

回答

0

的解決這個問題是增加行:在調用之前

response.AddHeader("Content-Length",size.ToString()); 

到的TransmitFile()。 學分歸Jim Schubert所有(請參閱上面的評論)。

0

Response.End()調用Response.Flush()。嘗試刪除刷新呼叫。

+0

我是故意的;我想在「響應」消失之前將「ok」標誌設置爲true,並且在沖洗之後無論如何,這並沒有解決問題,吉姆上面提出了一個建議,但是,謝謝你的評論。 – ileon 2010-07-01 08:56:39