Download of binary files

Results 1 to 4 of 4

Thread: Download of binary files

  1. #1
    Chrace Guest

    Default Download of binary files

    Some might have seen my distressed posts around the boards. Here&#039s the full story.<BR><BR>I need to make a download of binary files from the server. I am using a virtual directory structure and thus cannot link directly to the file (physical name is different).<BR>I have successfully gotten SoftArtisans FileManager component running with this (method OpenBinaryFile), but I need to get the full application running with no use of 3rd party components.<BR><BR>I have two ideas I am working on to get it working. One is using the Scripting.FileSystemObject to grab the file and dump this into the Response object.<BR>The other creates an ADODB.Stream object and uses the LoadFromFileMethod. The idea is then to stream the data to the Response object.<BR><BR>Code examples:<BR>*** Method 1, using Scripting.FileSystemObject ***<BR>Response.ContentType = sContentType<BR>Response.Addheader "Content-Disposition", "attachment; filename=" & sFileName<BR><BR>Set oFS = Server.CreateObject( "Scripting.FileSystemObject" )<BR>Set oFile = oFS.GetFile( sPath )<BR><BR>Response.AddHeader "Content-Length", oFile.Size<BR><BR>Response.BinaryWrite( oFile )<BR><BR>*** Method 2, using ADODB.Stream ***<BR>Response.ContentType = sContentType<BR>Response.Addheader "Content-Disposition", "attachment; filename=" & sFileName<BR><BR>Set oBS = Server.CreateObject( "ADODB.Stream" )<BR>oBS.Open<BR>oBS.LoadFromFile( sPath )<BR>Response.BinaryWrite( oBS.Write( oBS.Size ) )<BR>oBS.Close<BR><BR>- - - - - - - - - - - - - - - - - - - - - <BR><BR>None of these works as they have been put here. I have tried several different versions of the above code but none gets close. Comments, ideas, correction of major mistakes and general discussion welcome.<BR><BR>Chrace

  2. #2
    John M. Guest

    Default RE: Download of binary files

    I have got this sorta working on my server. It looks like you are missing 1 key piece -- the correct "Content-Type". I tried using the types "application/x-msdownload", "application/octet-stream", and "application/unknown" all to no avail. The download file always kept showing up in the browser. I finally got it to work when I changed the type to "text/plain". Suddenly, I started to get the File Download box in the browser!<BR><BR>BTW, this trick works well on "no-frames" pages. If it&#039s called from inside a frame, the document dies! Now if only I can figure out how to fix it...

  3. #3
    Chrace Guest

    Default RE: Download of binary files

    Thanks for the response, but IE still overrules the content type - meaning that if want to download an HTML, PDF or JPEG/GIF file it still gets shown instead of downloaded. And if you try text/plain with an ASP file, well, you get all the code shown as text as well.<BR><BR>Don&#039t really know what to do about this. So far I have abandoned the idea - can&#039t win a fight with neither IE nor Netscape anyway..

  4. #4
    Richard A. Lowe Guest

    Default RE: Download of binary files

    Before I answer I must clarify: When you say virtual directory structure, what exactly do you mean? <BR><BR>1) Are you using one virtual web folder? If so, it&#039s easy to resolve the full path of the file and use some direct appoach to getting the file.<BR><BR>2) Or multiple virtual web folders? If so, it will be tougher to link directly to the physical path, but might be obtainable but other methods.<BR><BR>3) Or are you linking to files that are on other web servers? (and therefore only available via HTTP requests).<BR><BR>4) something else???<BR><BR>Let me know,<BR>Richard

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts