2017-10-13 2 views
0

ASP.NET (VB.NET)에서 다운로드 한 후 파일을 여는 동안 원격 서버 공유 경로에 파일이있는 경우 다음과 같은 오류가 발생합니다.다운로드 후 파일이 손상됨

사용 된 다음 코드는 파일을 다운로드하는 것입니다 : Wiktor Zychla에 동의

Private Sub downloadFile(ByVal file As String) 

    Try 
     Dim requestFile As String = "\\ashleyfurniture\afi-dfs\Arcadia\Vaults\Web\AshleyDirectAttachments\IdeaNetwork\Images" + "\" + file 

     If String.IsNullOrEmpty(requestFile) Then 
      Throw New FileNotFoundException("File to download cannot be null or empty") 
     End If 

     ' Get file name from URI string in C# 

     Dim uri = New Uri(requestFile) 
     Dim filename As String = Path.GetFullPath(uri.OriginalString) 
     Dim fileInfo = New FileInfo((uri.OriginalString)) 

     If Not fileInfo.Exists Then 
      Throw New FileNotFoundException("File to download was not found", uri.OriginalString) 
     End If 


     Response.ContentType = "application/octet-stream" 

     Response.AddHeader("Content-Disposition", "attachment; filename=""" + fileInfo.Name + """") 
     Response.WriteFile(fileInfo.FullName) 
     Response.End() 



     ' ignore exception 
    Catch generatedExceptionName As ThreadAbortException 

    Catch ex As FileNotFoundException 
     Response.StatusCode = CInt(System.Net.HttpStatusCode.NotFound) 
     Response.StatusDescription = ex.Message 
    Catch ex As Exception 
     Response.StatusCode = CInt(System.Net.HttpStatusCode.InternalServerError) 
     Response.StatusDescription = String.Format("Error downloading file: {0}", ex.Message) 
    End Try 



End Sub 
+0

의 ContentType을 제거하십시오 16 진수 편집기 (또는 심지어 텍스트 편집기), 웹 페이지 인 것처럼 보이는 텍스트로 시작합니까? –

+0

파이프 라인이 현재 처리 된 페이지를 여기에 추가하지 않도록하기 위해'Response.ContentType' 바로 전에'Response.Clear()'가 없습니다. response.End() 앞에 Response.Flush()를 추가합니다. –

답변

0

당신이에서 손상된 파일을 열 경우 응답

Response.ContentType = "application/octet-stream" 
관련 문제