how to response.write bytearray?

Viewed 47146

This is not working:

byte[] tgtBytes = ...

Response.Write(tgtBytes);
3 Answers

You're probably looking for:

Response.BinaryWrite(tgtBytes);

MSDN documentation here.

Response.OutputStream.Write(tgtBytes, 0, tgtBytes.Length);

If you want to output hex values

byte[] tgtBytes = ...
foreach (byte b in tgtBytes)
    Response.Write("{0:2x}", b);

Or do you want to do;

Response.Write(System.Text.Encoding.ASCII.GetString(tgtBytes));

To convert the bytes to ASCII text and output a string.

Related