[thelist] Retrieving OLE File from Access DB with Classic ASP

Ken Schaefer Ken at adOpenStatic.com
Mon Dec 19 18:43:49 CST 2005


a) Whether a browser opens a file using the configured file handler, or
prompts the user to open/save the file is a client-side setting. You can't
directly influence this from the server. The way to "trick" the browser is to
set the content-type to something that the client doesn't have a configured
handler for (though the purists on the list will decry that type of approach)

b) Streaming binary data from the file system, or from a database, is exactly
the same. The only issue you may be running into is getting the data out of
the database first. I could ensure that you've read all the data out of the
database (rather than setting the Stream's contents to a recordset's field
object) first, and then stream that to the client.

c) In the code below, you aren't using your Stream object at all. At the
moment you are assigning oRs("fldBinaryData") to myContents, and then
Response.BinaryWrite() myContents. The Stream object is being opened, and
then closed.

d) You might want to have a look at this article (though it pertains to Memo
fields, rather than OLE fields, but I think the issue is the same - large
data fields):
This article shows how to use GetChunk and AppendChunk methods:



-----Original Message-----
From: thelist-bounces at lists.evolt.org
[mailto:thelist-bounces at lists.evolt.org] On Behalf Of Chris
Sent: Monday, 19 December 2005 11:03 PM
To: thelist at lists.evolt.org
Subject: Re: [thelist] Retrieving OLE File from Access DB with Classic ASP

Sorry, lack of explanation is because I hadn't written any code to try and
pull the PDF from the database as I don't know how.

I just had a play and the following code [left out the database connection
bits] will open the PDF in the browser [IE and Mozilla]:

Response.Buffer = True
Response.ContentType = oRs("fldFileType")
Response.BinaryWrite oRs("fldBinaryData")

I was looking for an option to force the browser to download the data.
There are plenty of examples of streaming a file from the filesystem but not
for lifting binary data from a database then streaming it to the browser.

I've tried using:

Dim objStream, myContents, myFileName

myFileName = "file.txt"

Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" &

Set objStream = Server.CreateObject("ADODB.Stream")

myContents = oRs("fldBinaryData")

Response.BinaryWrite myContents

Set objStream = Nothing

The ADODB Stream does not like being set to the database field and throws a
type mismatch error.  I suspect it will only work being fed a file from the

Thanks for the help so far.

> -----Original Message-----
> From: thelist-bounces at lists.evolt.org [mailto:thelist-
> bounces at lists.evolt.org] On Behalf Of Ian Anderson
> Sent: 19 December 2005 09:39
> To: thelist at lists.evolt.org
> Subject: Re: [thelist] Retrieving OLE File from Access DB with Classic ASP
> Chris wrote:
> > I'd like to be able to provide options to open the PDF in a browser
> window
> > and to stream it to the client's browser as a 'save to' option.
> You haven't said what actually happens in the browser when you try your
> code.
> Does it fill the screen with garbage, or give an error message?
> I'm wondering about setting content-type in the header, or something
> like that - the browser is expecting html or image data, but may be
> receiving the raw binary data from the PDF and trying to interpret it
> using its default settings.
> More explanation of what is seen to be happening would surely help
> Cheers
> Ian

More information about the thelist mailing list