APGen Documentation Previous Topic: Output.Write() Next Topic: Output.ClearBuffer() Parent Topic: Output Object    Output Object
Output.BinaryWrite()
See Also:

The Output.BinaryWrite() method writes a byte array to the output stream without any character-set conversion.

Syntax

VBScript:

Output.BinaryWrite data

JScript:

Output.BinaryWrite( data );

Parameters

data The data to be written to the output stream. Byte arrays (VT_ARRAY | VT_UI1), VBScript arrays of bytes, and JScript arrays of bytes, can be used.

Notes

This method is useful for writing non text information such as binary data.  Binary data may be required by a custom application.

The BinaryWrite method is similar to the Write() method, except it writes arrays of bytes to the output stream.  The value of Output.Unicode does not affect BinaryWrite().

Examples

The first example uses ADO to pull images from the Pubs database, which is included with SQL Server.  The script then uses Output.BinaryWrite() to write the images to GIF files:

<%#

    Set rs = Script.CreateObject("adodb.recordset")
    strSQL = "select logo, pub_id from pub_info"
    rs.Open strSQL, "Provider=SQLOLEDB;Initial Catalog = pubs;UserID=sa"

    Do While Not rs.EOF
          Output.Filename = CStr(rs("pub_id")) & ".gif"
          Output.BinaryWrite rs("logo")
          Output.Close
          
          rs.MoveNext
    Loop
     
    rs.Close
    Set rs = Nothing

#%>

The second example fills a JScript array with some numbers (a number can be a byte, as long as the numbers are between 0 and 255), and writes the array to a file using BinaryWrite().  This example leaves array entries 0, 20, and 21 empty - empty entries are written as byte 0x00. 

<%# @LANGUAGE=JScript #%>
<%#

// Write an array
Output.Filename = "test.js.bin";
var my_array = new Array(22);
for (i = 1; i < 20; i++)
    {
    my_array[i] = i;
    }

Output.BinaryWrite(my_array);
Output.Close();

#%>

The third example fills a VBScript array with some numbers, and writes the array to a file using BinaryWrite().  Note that array entries 0 and 21 are left empty.

<%#

' Write an array
Output.Filename = "test.bin"
Dim rgBytes(21)
For i=1 to 20
     rgBytes(i) = i
Next

Output.BinaryWrite rgBytes
Output.Close

#%>

Applies To

Output Object