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
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