Name

BinaryWrite — Request.BinaryWrite arbyteData

Synopsis

Writes information directly to the response content without any character conversion. If your application involves writing binary data to the client, you must use this method to ensure that data you send is not converted to character data from the original binary.

Parameters

arbyteData

An array of bytes you wish to write to the response content

Example

The following example code is lengthy for the simple call to BinaryWrite, but it demonstrates a very useful concept, especially if you are forced to deal with binary data from a database.

<% 

' The following code retrieves a binary object
' (in this case a JPG image) and writes it to the
' client using BinaryWrite. (For more information
' on ActiveX Data Objects usage, see Chapter 12.) ' Create an ADO connection object. Set adoCon = Server.CreateObject("ADODB.Connection") ' Use the Open method of the Connection object ' to open an ODBC connection with the database ' represented by the DSN ImageDatabase. adoCon.Open "ImageDatabase" ' Use the Execute method of the ADO Connection object ' to retrieve the binary data field from the database. Set adoRecImgData = adoCon.Execute _ ("SELECT ImageData FROM Images WHERE ImageId = 1234") ' Create a Field object by setting one equal to a ' specific field in the recordset created previously. Set adoFldImage = adoRecImgData("ImageData") ' Use the ActualSize property of Field object to retrieve ' the size of the data contained in the Field ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.