views:

102

answers:

1

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?

A: 
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

joshcomley
Do you know what I would do with the byte[] on the client side javascript?
John
What did you _want_ to do with it? What's in the file?
John Saunders
just open the file up in the pdf reader
John
Yes, what would you do with a file received by JavaScript? You can't (reliably) embed an image in such a way if that's your bag. If it is an image, there are better options.
joshcomley
What PDF reader? If it's some Flash thing I suspect you would point it at a URL as opposed to load in a file manually. If it's an iframe again you should just load a URL! In which case you could use the first part of my answer.
joshcomley
You can't use a pagemethod for this purpose. You just want a handler (.ashx file). This would have a URL with params: http://s/p.ashx?file=x.pdf. User or page would just browse to that URL and It would then return the x.pdf file set to open in browser.
John Saunders