2011-02-28 2 views
0


나는이 질문을 asp.net 웹 포럼에 게시했지만 아무도 대답하지 않았습니다.IE8에서 .pdf 파일을 열 수 없습니다.

내가 IE8을 사용하여 .pdf 파일의 "ONE"페이지를 열고 나에게 오류 메시지를 줄 수 없다 "파일이 손상되어 수리 할 수 ​​없습니다"SQL 서버 2008에서 검색,하지만 하나 이상의 페이지를 나는 아무런 문제없이 열 수있다.

크롬에서는 여러 개의 .pdf 페이지를 열 수 있습니다.

IE8을 사용하여 열 수없는 동일한 페이지가 IE8을 사용하여 하드 디스크에서 직접 열 수 있습니다. .asxh 파일

내 코드 :

context.Response.ContentType = "application/pdf" 
    Dim strm As Stream = ShowNewsImage(imgName) 
    If Not strm Is Nothing Then 
     Dim buffer As Byte() = New Byte(4095) {} 
     Dim byteSeq As Integer = strm.Read(Buffer, 0, 4096) 

     Do While byteSeq > 0 
      context.Response.OutputStream.Write(buffer, 0, byteSeq) 
      byteSeq = strm.Read(Buffer, 0, 4096) 
     Loop 
     context.Response.BinaryWrite(buffer) 
    End If 

감사합니다,

아메드.

+0

파일을 청크로 쓰는 이유는 무엇입니까? –

답변

0

Proble 해결.

버퍼를 Object에서 Byte로 변경했는데 작동했습니다!

이전 코드 (핸들러의 일부) : 보시다시피

context.Response.ContentType = "application/pdf" 
    Dim strm As Stream = ShowNewsImage(imgName) 
    If Not strm Is Nothing Then 
     Dim buffer As Byte() = New Byte(4095) {} 
     Dim byteSeq As Integer = strm.Read(buffer, 0, 4096) 

     Do While byteSeq > 0 
      context.Response.OutputStream.Write(buffer, 0, byteSeq) 
      byteSeq = strm.Read(buffer, 0, 4096) 
     Loop 
     context.Response.BinaryWrite(buffer) 
     context.Response.End() 
    End If 
End Sub 

Public Function ShowNewsImage(ByVal imgName As String) As Stream 
    Dim conn As String = ConfigurationManager.ConnectionStrings("Connection").ConnectionString 
    Dim connection As SqlConnection = New SqlConnection(conn) 
    Dim sql As String = "SELECT image FROM Table WHERE ID = @ID" 
    Dim cmd As SqlCommand = New SqlCommand(sql, connection) 
    cmd.CommandType = CommandType.Text 
    cmd.Parameters.AddWithValue("@ID", imgName) 
    connection.Open() 
    Dim img As <strong>Object </strong>= cmd.ExecuteScalar() 
    Try 
     Return New MemoryStream(CType(img, Byte())) 
    Catch 
     Return Nothing 
    Finally 
     connection.Close() 
    End Try 
End Function 

, ExecuteScalar는()는 오브젝트에의 출력을 첨부. 내가 바이트이 변경 :

context.Response.ContentType = "application/pdf" 
    Dim buffer As Byte() = New Byte(4095) {} 
    Dim byteSeq As Integer = 0 
    Dim conn As String = ConfigurationManager.ConnectionStrings("Connection").ConnectionString 
    Dim connection As SqlConnection = New SqlConnection(conn) 
    Dim sql As String = "SELECT image FROM Table WHERE ID = @ID" 
    Dim cmd As SqlCommand = New SqlCommand(sql, connection) 
    cmd.CommandType = CommandType.Text 
    cmd.Parameters.AddWithValue("@ID", imgName) 
    connection.Open() 

    buffer = cmd.ExecuteScalar() 

    context.Response.BinaryWrite(buffer) 
    context.Response.End() 

context.Response.OutputStream.Write 필요, 이미

context.Response.BinaryWrite

에 방해되는 이틀 나를했다.

0

PDF를 완료 한 후 Response.buffer를 true로 설정하고 response.flush를 true로 설정하십시오.

+0

감사합니다 VSU, 나는 그것을 시도했지만 손상된 파일 및 메시지 "파일이 손상되어 복구 할 수 없습니다" – Ahmed

0

너무 뻔한 것 같지만 물어볼 필요가 있습니다. 당신이 이것을 시도 했습니까?

Response.WriteFile(imgName) 

Link to documentation 당신이 이것을 잘 모른다면. :)

+0

답장을위한 섀도 마법사 감사합니다 – Ahmed

관련 문제