2009-12-07 6 views
2

다음 코드를 사용하여 pdf 파일을 다시 사용자에게 보냅니다. 이것은 내 PC와 우리의 모든 테스트 PC에서 잘 작동합니다. 그러나 사용자가 문서가 손상되었다고 불평하고 있습니다. 메모장에서 보낸 pdf 파일을 보면 이진 정보 뒤에 HTML이 표시됩니다.손상된 파일을 반환하는 PDF

protected void btnGetFile_Click(object sender, EventArgs e) 
     { 
      string title = "DischargeSummary.pdf"; 
      string contentType = "application/pdf"; 
      byte[] documentBytes = GetDoc(DocID); 

      Response.Clear(); 
      Response.ContentType = contentType; 
      Response.AddHeader("content-disposition", "attachment;filename=" + title); 
      Response.BinaryWrite(documentBytes); 
     } 

답변

5

문제는 파일의 끝에 추가 응답 오브젝트에 의해 원인은 파일의 끝 부분에있는 페이지의 구문 분석 HTML 바이트입니다. 이것은

파일을 버퍼에 쓴 후 Response.Close()를 호출하여 방지 할 수 있습니다.

protected void btnGetFile_Click(object sender, EventArgs e) 
     { 
      string title = "DischargeSummary.pdf"; 
      string contentType = "application/pdf"; 
      byte[] documentBytes = GetDoc(DocID); 

      Response.Clear(); 
      Response.ContentType = contentType; 
      Response.AddHeader("content-disposition", "attachment;filename=" + title); 
      Response.BinaryWrite(documentBytes); 
      Response.End(); 
     } 
+0

매력적인 작품. 그것은 나를 돕고 내 문제를 해결했습니다. 고마워요 @ 존 너른 – Mehmood

관련 문제