PDF File stream problem... HELP...

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
 
G

Guest

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")
 
G

Guest

OK...

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

Strange???

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top