Retrieve pdf files from SQL Server

Discussion in 'ASP General' started by Jeff Fenn, Feb 27, 2004.

  1. Jeff Fenn

    Jeff Fenn Guest

    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
     
    Jeff Fenn, Feb 27, 2004
    #1
    1. Advertising

  2. Jeff Fenn

    Patrick G. Guest

    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" <> wrote in message
    news:...
    > 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
     
    Patrick G., Feb 27, 2004
    #2
    1. Advertising

  3. Jeff Fenn

    Jeff Guest

    Thanks, that worked.
     
    Jeff, Mar 1, 2004
    #3
  4. Jeff Fenn

    Patrick G. Guest

    Glad to hear... good luck.

    "Jeff" <> wrote in message
    news:...
    > Thanks, that worked.
     
    Patrick G., Mar 2, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Robert Wehofer

    Retrieve SQL Server 2000 rights for a user

    Robert Wehofer, Nov 12, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    318
    Robert Wehofer
    Nov 12, 2003
  2. =?Utf-8?B?U3JpZGhhcg==?=
    Replies:
    3
    Views:
    2,144
    n33470
    Dec 13, 2005
  3. crazyprakash
    Replies:
    4
    Views:
    3,421
    adrian
    Oct 30, 2005
  4. Ricardo Pog
    Replies:
    1
    Views:
    470
    Austin Ziegler
    Mar 26, 2008
  5. Sean Nakasone
    Replies:
    1
    Views:
    413
    Farrel Lifson
    Apr 14, 2008
Loading...

Share This Page