IO Stream HELP URGENT!!!

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

Does anyone know how to send an IO stream to the browser? Preferably in a
new window.

Thanks in Advance.
 
Response.BinaryWrite does not accept a stream data type.
Can you provide an example of how to use OutPutStream in this way?
 
If your System.IO.Stream is a System.IO.MemoryStream you can just call
Response.BinaryWrite(memoryStream.ToArray());
If it is not, maybe the object you want to output provides
a method for saving to a System.IO.Stream, like System.Drawing.Image does;
then you can just do this:
myImage.Save(Response.OutputStream);

If not, do:
(where "stream" variable represent the System.IO.Stream instance you want to
output):

byte [] data = new byte [stream.Length];
stream.Read(data, 0x0, data.Length);
Response.BinaryWrite(data);

This will fill a byte array with the content of "stream" and write to the
response output stream.

Note; always clear the response before writing binary data,
otherwise the binary data might get corrupted.
Do this by calling
Response.Clear();
Response.ClearContent();

prior to the binary write operation.

Also, you should provide information about the content type of the binary
data that will be written
to the response object, eg:
Response.ContentType = "image/png";
if it is a PNG binary stream.

Regards, Dennis
 
Back
Top