Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 34,223 times

Related Categories

Sending binary data with ASP

Lio_889


There are situations where you need to have your ASP page sending binary data to the client. As you might now, there's no direct ASP code for reading a binary file, that's why we need to use an external component for retrieving the binary file.

But instead of writing our own component, why not using the existing ones? The ADO object, which is found on any IIS web server was written to manipulate databases, and since databases are binary files, the ADO object can read our binary files...

<%

Function getBinaryFile(strFilePath)

  Dim TypeBinary, oStream
 
 
  TypeBinary = 1   ' Indicates a binary file
 
  ' Create the object
  Set oStream = Server.CreateObject("ADODB.Stream")
 
  ' Open our file
  oStream.Open
 
  ' Retreive binary data from the file
  oStream.Type = TypeBinary
  oStream.LoadFromFile strFilePath
 
 
  ' Return the binary data to the caller
  getBinaryFile = oStream.read
 
  ' Destroy the ADO object  
  Set oStream = Nothing

End Function
 
Response.BinaryWrite getBinaryFile(Server.MapPath("\my_file\thefile.bin"))

%>

Comments

  • Passing Binary Files to the User

    Posted by kiqkinas on 09 Apr 2003

    I've altered your code just a little and it works but it doesn't exactly solve my problem. See http://flyinghands.com/a_Download0.asp

    This works as long as the file being downloaded is located on...

  • Sending Hidden PDF's to the Browser

    Posted by scottuk on 17 Jan 2003

    Using the following two articles i managed to get the result I needed ,

    [url="http://www.developerfusion.com/show/2542"]http://www.developerfusion.com/show/2542[/url]

    [url="http://www.developer...

  • opening a binaryfile in read/write mode

    Posted by Pavanj on 19 Dec 2002

    I tried using oStream.mode=3 (in the article "sending binary data with Asp") but I am unable to open a word document in read/write mode. Does anyone have a solution for this?
    Thanks

    Pavan