CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Downloading is using web address!

Print topic Send  topic

Author Message
smalloy

Posts: 107
Posted: 05/24/2006, 1:11 PM

I'm having some issues getting a simple downlaod page to work. When the Open / Save / Cancel screen pops up the NAME of the file seems to be the page itself! Also the TYPE is HTML so it is the page.

Here is the code I use - also the files (there are 3 and the user can choose) are all pdf's.

  
Private Sub DownloadFile(file)    
  
     '--declare variables    
     Dim strAbsFile    
     Dim strFileExtension    
     Dim objFSO    
     Dim objFile    
     Dim objStream  
     '-- set absolute file location    
     strAbsFile = Server.MapPath(file)    
    '-- create FSO object to check if file exists and get properties    
     Set objFSO = Server.CreateObject("Scripting.FileSystemObject")    
  
    '-- check to see if the file exists    
     If objFSO.FileExists(strAbsFile) Then    
         Set objFile = objFSO.GetFile(strAbsFile)    
  
         '-- first clear the response, and then set the appropriate headers    
         Response.Clear    
  
         '-- the filename you give it will be the one that is shown    
         ' to the users by default when they save    
         Response.AddHeader "Content-Disposition", "attachment; filename='" & objFile.Name & "'"  
         Response.AddHeader "Content-Length", objFile.Size  
         Response.ContentType = "application/octet-stream"  
         Set objStream = Server.CreateObject("ADODB.Stream")    
         objStream.Open    
  
         '-- set as binary    
         objStream.Type = 1    
         Response.CharSet = "UTF-8"    
  
         '-- load into the stream the file    
         objStream.LoadFromFile(strAbsFile)    
  
         '-- send the stream in the response    
         Response.BinaryWrite(objStream.Read)    
         objStream.Close    
         Set objStream = Nothing    
         Set objFile = Nothing    
     Else 'objFSO.FileExists(strAbsFile)    
         Response.Clear    
         Response.Write("No such file exists.")    
     End If    
     Set objFSO = Nothing    
 End Sub   

Thank you - I am quite frustrated.
_________________
Anything can be done, just give me time and money.
View profile  Send private message
smalloy

Posts: 107
Posted: 05/24/2006, 1:41 PM

Here is solution.

Response.Flush

just above
Response.BinaryWrite(objStream.Read)

Thanks for listiening!
Steve
_________________
Anything can be done, just give me time and money.
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.