Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Help with download
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Help with download

 Post Reply Post Reply
Author
Awangku View Drop Down
Groupie
Groupie


Joined: 15 November 2001
Location: Malaysia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote Awangku Quote  Post ReplyReply Direct Link To This Post Topic: Help with download
    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

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.