Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active August 25, 2021 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/184c6265993d61b5f7a8f106835337dc to your computer and use it in GitHub Desktop.
Save GroupDocsGists/184c6265993d61b5f7a8f106835337dc to your computer and use it in GitHub Desktop.
Extract ZIP Archives Data in C#
// Extract ZIP Archives Data in C#
using (Parser parser = new Parser(@"path/sample.zip"))
{
// Extract attachments from the container
IEnumerable<ContainerItem> attachments = parser.GetContainer();
// Iterate over collection of entities
foreach (ContainerItem item in attachments)
{
// Print the FILE INFO
Console.WriteLine("-----------------------------------");
Console.WriteLine("Name: " + item.Name);
Console.WriteLine("File Size: " + item.Size + " Bytes");
Console.WriteLine("-----------------------------------");
try
{
using (Parser attachmentParser = item.OpenParser())
{
// Extract the ZIP entity text
using (TextReader reader = attachmentParser.GetText())
{
Console.WriteLine(reader == null ? "No text" : reader.ReadToEnd());
}
}
}
catch (UnsupportedDocumentFormatException)
{
Console.WriteLine("Isn't supported.");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment