Wednesday 12 September 2012

download pdf file in ASP


Code for Downloading  PDF file in ASP using ADODB Stream Object
-----------------------------------------------------------------------------------------------------------------
<%
Dim prvURL
prvURL="http://sqlinjectiontruths.blogspot.in/test.html"
prvURL=replace(prvURL,"http://","")
prvURL=replace(prvURL,Request.ServerVariables("HTTP_HOST"),"")

dim pdfURL
Select Case prvURL
Case "test.html"
pdfURL="test.pdf"
Case Else
Response.redirect("/")
End Select


    Response.ContentType = "application/x-unknown" ' arbitrary
    FPath =  Server.MapPath(".")&"\documents\"&pdfURL
    Response.AddHeader "Content-Disposition","attachment; filename="&pdfURL

    Set adoStream = CreateObject("ADODB.Stream")
    adoStream.Open()
    adoStream.Type = 1
    adoStream.LoadFromFile(FPath)
    Response.BinaryWrite adoStream.Read()
    adoStream.Close
    Set adoStream = Nothing
%>
-------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment