Retrieve pdf files from SQL Server

J

Jeff Fenn

Hi

Doesn anyyone know the proper lines of ASP code to sucessfully retrieve a pdf file from SQL server. Everytime I run my code I get gibberish all over the screen. I would like it to prompt me to save the file to disk

Thanks

-Jeff
 
P

Patrick G.

I don't know if this is what your looking for but see code below

I use this in a file called getfile.asp. On a web page listing documents (of
any type really) you would click a link to the getfile.asp sending the file
name and an action in the querystring.

For this example sending Now or Later as the action will either do the Save
As prompt or will open the document in the browser window.

There is also a call to a stored proc that will track the amount of times
the file was accessed.

Hope this helps.
=================
Dim strFile, strFileAction

strFile = Request.QueryString("file")
strFileAction = Request.QueryString("action")

If strFile <> "" Then
Call ExecQuery(connString, "EXEC procPublic_LibFileClick '" & strFile &
"'")
If strFileAction = "later" Then
'On Error Resume Next

Dim strFilePath, strFileSize, strFileExt, strFileType
Dim objSendFile

strFilePath = Server.MapPath(strFile)
'Response.Write strFilePath

'Set objSendFile = Server.CreateObject("Persits.Upload")
'objSendFile.SendBinary strFilePath, True, "application/octet-stream",
True

Set objSendFile = Server.CreateObject("ADODB.Stream")
objSendFile.Open
objSendFile.LoadFromFile strFilePath

Response.ContentType = "xxx/xxx"
Response.AddHeader "content-disposition", "attachment; filename=" &
strFile
Response.BinaryWrite objSendFile.ReadText
Set objSendFile = Nothing

If Err.Number <> 0 Then
'Call TrapError(Err.Number, Err.Description, Err.Source)
End If
ElseIf strFileAction = "now" Then
With Response
.Write "<html><head></head><body onload=""window.document.location='" &
strFile & "'""></body></html>"
End With
End If
End If


Jeff Fenn said:
Hi,

Doesn anyyone know the proper lines of ASP code to sucessfully retrieve a
pdf file from SQL server. Everytime I run my code I get gibberish all over
the screen. I would like it to prompt me to save the file to disk.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top