Create a Stream without having a physical file to create from

jhorton picture jhorton · Apr 12, 2010 · Viewed 40.7k times · Source

I'm needing to create a zip file containing documents that exist on the server. I am using the .Net Package class to do so, and to create a new Package (which is the zip file) I have to have either a path to a physical file or a stream. I am trying to not create an actual file that would be the zip file, instead just create a stream that would exist in memory or something.

My question is how do you instantiate a new Stream (i.e. FileStream, MemoryStream, etc) without having a physical file to instantiate from.

Answer

Robert Harvey picture Robert Harvey · Apr 12, 2010

MemoryStream has several constructor overloads, none of which require a file.