Is there anyway to stream a file stored in a database directly to an AxAcroPDF control?

Posted on 2007-08-10
Last Modified: 2008-01-09
I have a database that I store PDF files in.  I retreive these files using the below routine by retreiving the binary data into an array and then saving that array data to a file on the hard drive as a PDF.  I can then display the PDF in an AxAcroPDF control.  This code works perfectly.

    Sub GetFile(ByVal table As String, ByVal field As String, ByVal filename As String, ByVal condition As String)
        'Retreives binary data from database and loads it into a file.
        Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM " & table & " WHERE " & condition, connectionString)
        Dim ds As New DataSet()

            arr = ds.Tables(0).Rows(0).Item(field)  'Retieve data into the binary array.
            FileOpen(1, filename, OpenMode.Binary)  'Open file
            FilePut(1, arr)                         'Dump data into file.
            FileClose(1)                            'Close file
        Catch ex As Exception
            Exit Sub
        End Try
    End Sub

My Question is:
Is there anyway to stream the file directly from the database to the AxAcroPDF control without first saving the file on the hard drive?
Question by:NevSoFly
    LVL 27

    Accepted Solution

    Hello NevSoFly,
    Looks to me like using a MemoryStream would be the way to go.
    Save to memory, then read to memory.
    You will have to use a stream object instead of FileOpoen, etc.

    More on MemoryStream here:



    Author Comment

    Ok, I think I understand some of what's going on in the sample from the link.  But could you please show me how I would modify my subroutine, or should this now be a function returning the memory stream?

    In my original code I would call the subroutine to create the file and then open.

    GetFile("tblREVs", "ASSEMBLY_BINARY", FileName, "ASSEMBLY_NUMBER = '" & PN & "' AND ASSEMBLY_REV = '" & Me.cboRevision.Text & "'")
    Me.AxAcroPDF1.src = FileName

    Author Comment

    Dabas provided a link to use a MemoryStream.  I later found out that this may well work for some controls, but the AxAcroPDF control that I was using does not support this.  Its still good info at the link.
    LVL 27

    Expert Comment

    I still think you should use a MemoryStram if possible.
    You are calling GetFile with a FileName. Can you show the code you tried when instead of FileName you use a MemoryStream? I might be able to help you out then.
    What does the specification say AxAcroPDF.src is? Is it a string, or is it a stream, or an object?



    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now