|
I'm trying to include a "Download File" option in my company's website so that visitors don't have to right-click to download a PDF file. Can anybody help me with the codes below? For some reason, I can't get the thing to work. I managed to get the Save File dialog box and actually downloaded the file but the size stayed at 0 kb.
Dim objASPFSO, objASPFile Dim strFileName Dim strInput, strOutput Dim bProcessString
strFileName = Request.QueryString("file") strOutput = ""
' Conditional limiting use of this file
If InStr(1, strFileName, "\", 1) Then strFileName="" If InStr(1, strFileName, "/", 1) Then strFileName=""
If strFileName <> "" Then strFileName = Left(strFileName, Len(strFileName) - 4)
Set objASPFSO = CreateObject("Scripting.FileSystemObject") Set objASPFile = objASPFSO.OpenTextFile(Server.MapPath(strFileName & ".pdf"))
' Loop Through Real File and Output Results to Browser Do While Not objASPFile.AtEndOfStream strInput = objASPFile.ReadLine ' If we find Begin Script Tag start processing If InStr(1, strInput, "<!-- BEGIN " & "SCRIPT -->", 1) Then bProcessString = 1 strInput = objASPFile.ReadLine End If ' If we find End Script Tag stop processing If InStr(1, strInput, "<!-- END " & "SCRIPT -->", 1) Then bProcessString = 0
If bProcessString = 1 Then Response.Write strInput & vbCrLf strOutput = strOutput & strInput & vbCrLf End If Loop
objASPFile.Close Set objASPFile = Nothing Set objASPFSO = Nothing
Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName & ".pdf" Response.ContentType = "application/octet-stream" Response.Write strOutput
Else
Response.Write "File is not available!"
End If
|