PDF File stream problem... HELP...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim::..

    PDF File stream problem... HELP...

    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
  • Curt_C [MVP]

    #2
    RE: PDF File stream problem... HELP...

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

    Response.AddHea der("Content-Disposition", "inline;filenam e=form.pdf")

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com



    "Tim::.." wrote:
    [color=blue]
    > 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[/color]

    Comment

    • Tim::..

      #3
      RE: PDF File stream problem... HELP...

      OK...

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

      Strange???

      Thanks


      "Curt_C [MVP]" wrote:
      [color=blue]
      > not sure what this does but I've seen most examples of this with the extra
      > "inline;" value...
      >
      > Response.AddHea der("Content-Disposition", "inline;filenam e=form.pdf")
      >
      > --
      > Curt Christianson
      > site: http://www.darkfalz.com
      > blog: http://blog.darkfalz.com
      >
      >
      >
      > "Tim::.." wrote:
      >[color=green]
      > > 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[/color][/color]

      Comment

      Working...