PDF File stream problem... HELP...

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Can someone please tell me why I can't open PDF's from a database but I can
open all other types of files...

I have acrobat reader 7 installed on my client and there is no problem
opening normal PDF files but when I try to open a PDF using the following
code it either opens in notepad or comes up with the error...

The file is damaged and could not be repaired...
This isn't the case as I can open the same files in my old asp application...

The contenttype is set to application/pdf... I have also tried
application/octet-stream... niether work...

Thanks for any help!

Code...

Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim cmd As New SqlCommand("GetFileData", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objFileData As New SqlParameter

objFileData = cmd.Parameters.Add("@FileID", SqlDbType.NVarChar)

objFileData.Direction = ParameterDirection.Input
objFileData.Value = ID

Dim myReader As SqlDataReader = cmd.ExecuteReader()


While myReader.Read
Response.Expires = 0
Response.Buffer = True
Response.Clear()
Response.ContentType = myReader.Item("fileType") 'Setting
the file type of the retrieved file
Response.AddHeader("Content-Disposition",
"filename=mypdf.pdf")
Response.BinaryWrite(myReader.Item("Data")) 'Writing the
File retrieved from the database
Response.Flush()

End While

myReader.Close()
Myconn.Close()

End If

End Sub
 
not sure what this does but I've seen most examples of this with the extra
"inline;" value...

Response.AddHeader("Content-Disposition", "inline;filename=form.pdf")
 
OK...

Managed to fix it...
For some reason I had to a response.close() then PDF documents where
streamed ok...

Strange???

Thanks
 
Back
Top