Search code examples
c#streampackagesystem.io.packaging

Create a Stream without having a physical file to create from


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.


Solution

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