I’ve posted this question in asp.net web forum but no one replied.
I can’t open “ONE” page of .pdf file using IE8 and give me an error message “the file is damaged and could not be repaired” when retrieved from SQL Server 2008, but more than one page I can open with no problem.
With Chrome I can open any number of .pdf pages.
The same page that I can’t open using IE8 from DB, can be opened directly from hard disk using IE8.
My code in .asxh file:
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
Thanks,
Ahmed.
Proble solved.
I changed the buffer from Object to Byte and it worked !!!
The old code (part of a handler) :
As you see, ExecuteScalar() attached the output to an Object.
I changed this to Byte:
No need to context.Response.OutputStream.Write , it is already impeded in context.Response.BinaryWrite
Took me two days.