• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2605
  • Last Modified:

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

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

        da.Fill(ds)
        Try
            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?
0
NevSoFly
Asked:
NevSoFly
  • 2
  • 2
1 Solution
 
DabasCommented:
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:
http://msdn2.microsoft.com/en-us/library/system.io.memorystream.aspx


Regards,

Dabas
0
 
NevSoFlyAuthor Commented:
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
0
 
NevSoFlyAuthor Commented:
Everyone,
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.
0
 
DabasCommented:
Nev:
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?

Dabas

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now