Skip to main content

Posts

Showing posts with the label Excel

Zipping up files from a MemoryStream

Recently I needed to write some .NET code that zipped up some files and downloaded the zip without touching the file system. I struggled to find a good example, so I thought I’d post the code here … Assuming that we’ve got the source files in memory in the following structure: 1 2 3 4 5 6 public class SourceFile {      public string Name { get ; set ; }      public string Extension { get ; set ; }      public Byte [ ] FileBytes { get ; set ; } } We can use the following code to zip these files up and send the zip in the response: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 public ActionResult Index ( ) {      // get the source files      List < SourceFile > sourceFiles ...