2016-07-28 5 views
0

이 코드를 사용하여 파일을 다운로드하고 있지만 오류가 발생합니다. 취급을 도와주세요.내 코드가 스레드에서 오류를 발생시키는 이유는 무엇입니까?

스레드가 중단되었습니다.

protected void Download_Click(object sender, EventArgs e) 
{ 
    try 
    { 
     string filePath = Convert.ToString(Attachment); 
     string fullFilePath = ("../../SiteImages/" + "donald.jpg"); 
     Response.Clear(); 
     Response.ClearHeaders(); 
     Response.ClearContent(); 
     Response.AddHeader("Content-Disposition", "attachment; filename=\"" + Path.GetFileName(fullFilePath) + "\""); 
     Response.ContentType = ContentType; 
     Response.TransmitFile(fullFilePath); 
     //MngLogs.InsertAuditsInfo("Tender downloaded via" + " " + MngLogs.PageName, MngLogs.UserMacAddress, MngLogs.UserIPAddress, UserID, "Download"); 
     //Response.End(); 
    } 
    catch (Exception ex) 
    { 
     Utility.Msg_Error(Master, ex.Message); 
    } 
} 
+0

어디서 오류가 발생 했습니까? 'Reponse.End()'는 항상'ThreadAbortException'을 던집니다. [this] (http://stackoverflow.com/questions/20988445/how-to-avoid-response-end-thread-was-being-aborted-exception-during-the-exce)와 [this]를보십시오. (http://stackoverflow.com/questions/5834049/what-causes-thread-was-being-aborted-exception-to-happen-at-random-and-showthth) post. –

+0

예. 같은 위치에서 제거했지만 여전히 파일을 다운로드하지 않습니다. – Cuckoo

+0

오류가 발생하지 않지만 여전히 파일을 다운로드하지 않습니다. – Cuckoo

답변

0

이 다운로드 방식을 사용할 수 있습니까?

try 
{ 
    using (var client = new WebClient()) 
    { 
     client.DownloadFile(urlToFileOnInternet, pathToFileOnComputer); 
    } 
} 
catch (Exception ex) 
{ 
    Utility.Msg_Error(Master, ex.Message); 
} 

희망이 있습니다.

+0

urlToFileOnInternet은 무엇입니까? – Cuckoo

+0

파일을 다운로드하려고하지 않습니까? 인용구 : "이 코드를 사용하여 파일을 다운로드하고 있습니다" – MasterXD

+0

webserver에서 내 폴더로 파일을 다운로드 중입니다. – Cuckoo

0

이와

Response.End(); 

교체 : 그것은 현재 스레드를 중단됩니다 원인

HttpContext.Current.Response.Flush(); 
HttpContext.Current.Response.SuppressContent = true; 
HttpContext.Current.ApplicationInstance.CompleteRequest(); 

Response.End();

항상 예외를 throw합니다. 이 문제에 대한 자세한 내용은 Is Response.End() considered harmful?, How to Avoid Response.End() "Thread was being aborted" Exception during the Excel file download에서 확인할 수 있습니다.

+0

아직 작동하지 않습니다 – Cuckoo

+0

@Cuckoo가 내 업데이트를 확인합니다. – Lesmian

관련 문제