Search code examples
c#javascriptweb-servicesfile-iopagemethods

Returning a stream directly to the web browser


I am generating a file on the server and I do not want to write it to disk but instead return it to the client via a web service. What recommendations would you have to do this?


Solution

  • Response.OutputStream.Write(...)
    

    Or if you have a MemoryStream:

    MemoryStream ms = ...;
    ms.WriteTo(Response.OutputStream);
    

    Edit:

    If it's a SOAP web service, then just return a byte array from your web service method in your asmx.cs file