This project has moved and is read-only. For the latest updates, please go here.

SaveAs vs Stream

Dec 7, 2011 at 9:34 AM

What are the differences between those two methods?

When Should I use each?

Dec 7, 2011 at 11:18 AM

What do you mean by stream? You want to know difference between "SaveAs" and "GetAsByteArray" or "SaveAs(File ...)" and "SaveAs(Stream ...)" ?

 

Basically, they are all the same, but "SaveAs(File ....)" is one step forward, it will get your stream and return a file instead of "bunch of bytes".

 

In a nutshell:

* You want to save file in your server/local computer: SaveAs(File ...).

* You want to download: SaveAs(Stream ...) or "GetAsByteArray".

 

Dec 7, 2011 at 3:52 PM

I wasn't clear enough, sorry!

"You want to download:"  -- yes, this is my purpose.

The worksheet has a Stream property. My question is what is the differences between ws.SaveAs(Stream) and ws.Stream?

Dec 7, 2011 at 4:25 PM
Edited Dec 7, 2011 at 4:27 PM

I´m not tottaly sure....

Jan, pls correct me if I´m wrong....but I think Stream and SaveAs will be the same if you are not using encrypt package. You should always call SaveAs or GetAsByteArray, so it will works even with encrypt package.

 

Sample code to send stream to a web client:

                    Response.Clear();
                    Response.AddHeader("content-disposition""attachment;  filename=file.xlsx");
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";                    
                    Response.BinaryWrite(pck.GetAsByteArray());
                    Response.End();

Dec 7, 2011 at 9:11 PM

Thanks!

BTW, do you monitor the issue tracker  or it needs to be discussed here, in the disscusions?

http://epplus.codeplex.com/workitem/14527