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(C onfigurationSet tings.AppSettin gs("strConn"))
Dim cmd As New SqlCommand("Get FileData", Myconn)
cmd.CommandType = CommandType.Sto redProcedure
Myconn.Open()
Dim objFileData As New SqlParameter
objFileData = cmd.Parameters. Add("@FileID", SqlDbType.NVarC har)
objFileData.Dir ection = ParameterDirect ion.Input
objFileData.Val ue = ID
Dim myReader As SqlDataReader = cmd.ExecuteRead er()
While myReader.Read
Response.Expire s = 0
Response.Buffer = True
Response.Clear( )
Response.Conten tType = myReader.Item(" fileType") 'Setting
the file type of the retrieved file
Response.AddHea der("Content-Disposition",
"filename=mypdf .pdf")
Response.Binary Write(myReader. Item("Data")) 'Writing the
File retrieved from the database
Response.Flush( )
End While
myReader.Close( )
Myconn.Close()
End If
End Sub
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(C onfigurationSet tings.AppSettin gs("strConn"))
Dim cmd As New SqlCommand("Get FileData", Myconn)
cmd.CommandType = CommandType.Sto redProcedure
Myconn.Open()
Dim objFileData As New SqlParameter
objFileData = cmd.Parameters. Add("@FileID", SqlDbType.NVarC har)
objFileData.Dir ection = ParameterDirect ion.Input
objFileData.Val ue = ID
Dim myReader As SqlDataReader = cmd.ExecuteRead er()
While myReader.Read
Response.Expire s = 0
Response.Buffer = True
Response.Clear( )
Response.Conten tType = myReader.Item(" fileType") 'Setting
the file type of the retrieved file
Response.AddHea der("Content-Disposition",
"filename=mypdf .pdf")
Response.Binary Write(myReader. Item("Data")) 'Writing the
File retrieved from the database
Response.Flush( )
End While
myReader.Close( )
Myconn.Close()
End If
End Sub
Comment