0

How can I list directories in a zip file using ZipPackage? I would like to work with the zip file as if it was a folder structure on disk, i.e. list files and directories at the current level, open some of the files as needed, then go into every folder, and so on recursively.

If possible, I would like to avoid external dependencies and I am limited to .Net 4.0.

EDIT: To make the question more concrete, assume I would like to create the following structure, that corresponds to the contents of the zip file:

interface IDirectory
{
  IList<IDirectory> SubDirectories {get; }
  IList<IFile> Files{get; }
  string Name {get; }
  //other methods
}

interface IFile
{
  string Name {get; }
  void UnZip (IStream stream);
}
Grzenio
  • 35,875
  • 47
  • 158
  • 240
  • Do you know about the [`GetParts()` method](http://msdn.microsoft.com/en-us/library/system.io.packaging.package.getparts(v=vs.100).aspx) that [gives you all files and directories in the archive](http://stackoverflow.com/questions/507751/extracting-files-from-a-zip-archive-programmatically-using-c-sharp-and-system-io)? Or do you mean you want to bind this information to a UI? If the latter, what UI framework do you use, WinForms, WPF, HTML? – CodeCaster Feb 11 '14 at 14:56
  • @CodeCaster, I saw them in the manual, but I am not sure how to use them in my case... – Grzenio Feb 11 '14 at 15:10
  • What do you mean _not sure_? What do you want to do? Try the two links in my comment for more info. :) – CodeCaster Feb 11 '14 at 15:11
  • Maybe you can use [`ZipArchieve`](http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive.aspx) instead? Simply [enumerate entries](http://stackoverflow.com/a/14753848/1997232) and use some logic with `Path` methods. – Sinatr Feb 11 '14 at 15:11
  • @Sinatr, the interface to `ZipArchieve` seems a lot more reasonable, but I am stuck with .Net 4.0 :( – Grzenio Feb 11 '14 at 15:17

1 Answers1

0

ZipPackage doesn't seem to handle arbitrary zip archives, so I guess the answer to my question is: it is not possible.

Grzenio
  • 35,875
  • 47
  • 158
  • 240