Print Page | Close Window

Help with download

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=743
Printed Date: 29 March 2026 at 3:11am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Help with download
Posted By: Awangku
Subject: Help with download
Date Posted: 05 March 2003 at 4:32am

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




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net