This documentation is archived and is not being maintained.

HttpResponse.BinaryWrite Method

Writes a string of binary characters to the HTTP output stream.

[Visual Basic]
Public Sub BinaryWrite( _
   ByVal buffer() As Byte _
)
[C#]
public void BinaryWrite(
 byte[] buffer
);
[C++]
public: void BinaryWrite(
 unsigned char buffer __gc[]
);
[JScript]
public function BinaryWrite(
   buffer : Byte[]
);

Parameters

buffer
The bytes to write to the output stream.

Example

The following example reads a text file into a buffer and writes the buffer to the HTTP output stream.

[Visual Basic] 
Dim MyFileStream As FileStream
 Dim FileSize As Long
 
 MyFileStream = New FileStream("sometext.txt", FileMode.Open)
 FileSize = MyFileStream.Length
 
 Dim Buffer(CInt(FileSize)) As Byte
 MyFileStream.Read(Buffer, 0, CInt(FileSize))
 MyFileStream.Close()
 
 Response.Write("<b>File Contents: </b>")
 Response.BinaryWrite(Buffer)
    

[C#] 
FileStream MyFileStream;
 long FileSize;
 
 MyFileStream = new FileStream("sometext.txt", FileMode.Open);
 FileSize = MyFileStream.Length;
      
 byte[] Buffer = new byte[(int)FileSize];
 MyFileStream.Read(Buffer, 0, (int)FileSize);
 MyFileStream.Close();
 
 Response.Write("<b>File Contents: </b>");
 Response.BinaryWrite(Buffer);
    

[C++] 
FileStream* MyFileStream;
 __int64 FileSize;
 
 MyFileStream = new FileStream(S"sometext.txt", FileMode::Open);
 FileSize = MyFileStream->Length;
      
 Byte Buffer[] = new Byte[(int)FileSize];
 MyFileStream->Read(Buffer, 0, (int)FileSize);
 MyFileStream->Close();
 
 Response->Write(S"<b>File Contents: </b>");
 Response->BinaryWrite(Buffer);
    

[JScript] 
var myFileStream : FileStream
var fileSize : long

myFileStream = new FileStream("sometext.txt", FileMode.Open)
fileSize = myFileStream.Length

var buffer : Byte[] = new Byte[int(fileSize)]
myFileStream.Read(buffer, 0, int(fileSize))
myFileStream.Close()

Response.Write("<b>File Contents: </b>")
Response.BinaryWrite(buffer)

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

HttpResponse Class | HttpResponse Members | System.Web Namespace

Show: