How to provide an order to files included in a zip file created using dotnet Zip

I would like to be able to include a file with a given order when creating a zip when using DotNet Zip .

Files do not appear in the sequence they added to zip. Now the order looks random.

I would like to have xyz-Header, xyz-Summary files included first, and then the rest of the files.

XYZ-Header.csv

XYZ-Summary.csv

XYZ-Male.csv

XYZ-Female.csv

xyz , and the names of other files are programmatically determined , but header and summary files are always included.

Code snippet

private MemoryStream GetZip() { ZipFile zip = new ZipFile(); List<string, string> files = getFiles(); zip.AddEntry("xyz-Header.csv", getHeader(files )); zip.AddEntry("xyz-Summary", getSummary(files)); foreach (var x in files) { zip.AddEntry("xyz-" + x.Item1 + ".csv", x.Item2); } MemoryStream memoryStream = new MemoryStream(); zip.Save(memoryStream); memoryStream.position = 0; return memoryStream; } 

I would appreciate any help with this.

+5
source share
1 answer

There is no reason why you need to order files in zip, you can get a list of files and give it any order:

  using (ZipFile zip = ZipFile.Read(NameOfExistingZipFile)) { foreach (ZipEntry e in zip.Order(x => x.FileName)) { // do your styff e.Extract(); } } 
0
source

All Articles