Re: IO Stream HELP URGENT!!!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Dennis Myrén (dennis_at_oslokb.no)
Date: 03/24/04


Date: Wed, 24 Mar 2004 16:57:56 +0100

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
"Chris" <calhoun_chris@hotmail.com> wrote in message
news:e3mFg3aEEHA.576@TK2MSFTNGP11.phx.gbl...
> Response.BinaryWrite does not accept a stream data type.
> Can you provide an example of how to use OutPutStream in this way?
> "Dennis Myrén" <dennis@oslokb.no> wrote in message
> news:pHg8c.2683$px6.38412@news2.e.nsc.no...
> >
> > use Response.BinaryWrite
> > or Response.OutputStream
> >
> > "Chris" <calhoun_chris@hotmail.com> wrote in message
> > news:ufaCRkaEEHA.2968@TK2MSFTNGP12.phx.gbl...
> > > Does anyone know how to send an IO stream to the browser? Preferably
in
> a
> > > new window.
> > >
> > > Thanks in Advance.
> > >
> > >
> >
> >
>
>



Relevant Pages

  • Re: tomcat: possible to write a copy of the response to a file
    ... Now however I get a browser response but nothing is written to the disk ... one stream which could contain both character and binary data. ...
    (comp.lang.java.programmer)
  • Re: tomcat: possible to write a copy of the response to a file
    ... CharArrayWriter caw = new CharArrayWriter; caw.write); ... Now however I get a browser response but nothing is written to the ... thought there was just one stream which could contain both character and binary data. ...
    (comp.lang.java.programmer)
  • RE: HTTPS WebRequest and WebResponse
    ... > // Creates an HttpWebRequest for the specified URL. ... > // Displays all the headers present in the response received from the URI. ... > // Obtain a 'Stream' object associated with the response object. ... > StreamReader readStream = new StreamReader(ReceiveStream, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Read everything from socket
    ... There is no standard way to indicate a stream is finished ... line from the RETR command ... Or from the LIST command ... the actual byte length is given of the response steam. ...
    (perl.beginners)
  • HTTPS WebRequest and WebResponse
    ... // Creates an HttpWebRequest for the specified URL. ... // Displays all the headers present in the response received from the URI. ... // Obtain a 'Stream' object associated with the response object. ... StreamReader readStream = new StreamReader(ReceiveStream, ...
    (microsoft.public.dotnet.languages.csharp)