title: C#: Programmatically create a split zip file
body: <p>I want to create a zip file from a folder that it around 1.5GB, and have that zip file be split into chunks of 100MB. I've found quite a few threads on this, but nothing has quite worked out for me.</p>
  
  <p>First I tried System.IO.Compression, but found that it doesn't support splitting the zip files (please correct me if I'm wrong!).</p>
  
  <p>Next I tried Ionic.zip, which looked super easy, but every set of files I create is corrupted in some way (for example, the following code that uses the fonts directory as a test directory creates a set of files that I can't then open or unzip as an archive with either winzip or winrar):</p>
  
  <pre><code>using (var zipFile = new Ionic.Zip.ZipFile(Encoding.UTF8))
  {
      zipFile.AddDirectory("c:\\windows\\fonts", directoryPathInArchive: string.Empty);
      zipFile.MaxOutputSegmentSize = 100 * 1000000;
      zipFile.Save("c:\\users\\me\\test.zip");
  }
  </code></pre>
  
  <p>Finally, I've tried the 7z.dll and SharpCompress. Using the Command Line and the 7z.exe file, the following works perfectly:</p>
  
  <pre><code>7z.exe a "c:\users\me\test.zip" "c:\Windows\Fonts" -v100m
  </code></pre>
  
  <p>But the following code gives the error "Value does not fall within the expected range."</p>
  
  <pre><code>SevenZipCompressor.SetLibraryPath("c:\\program files\\7-zip\\7z.dll");
  var compressor = new SevenZipCompressor();
  compressor.CompressionMethod = CompressionMethod.Lzma2;
  compressor.CustomParameters.Add("v", "100m");
  compressor.CompressDirectory("c:\\windows\\fonts\\", "c:\\users\\me\\test.zip");
  </code></pre>
  
  <p>I've also tried the following (having tried to figure out how the command line switches work in SharpCompress) which does create a zip file, but doesn't split it up:</p>
  
  <pre><code>SevenZipCompressor.SetLibraryPath("c:\\program files\\7-zip\\7z.dll");
  var compressor = new SevenZipCompressor();
  compressor.CompressionMethod = CompressionMethod.Lzma2;
  compressor.CustomParameters.Add("mt", "on");
  compressor.CustomParameters.Add("0", "LZMA2:c=100m");
  compressor.CompressDirectory("c:\\windows\\fonts\\", "c:\\users\\me\\test.zip");
  </code></pre>
  
  <p>Does anyone know why any of the above methods aren't working? Or are there any other ways that people have got working that I haven't tried yet?</p>
  
  <p>Thanks!</p>