Last active
August 25, 2021 09:49
-
-
Save GroupDocsGists/184c6265993d61b5f7a8f106835337dc to your computer and use it in GitHub Desktop.
Extract ZIP Archives Data in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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