Extract text from ZIP archive files

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Parser MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-parser -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-parser/parser-net-mcp:latest
Folders, licensing and more →

To extract files from ZIP archives GetContainer method is used. This method returns the collection of ContainerItem objects.

Zip Entry can contain the following metadata:

NameDescription
dateThe time and date at which the file indicated by the Zip Entry was last modified.

These metadata refer to a container element itself, not a document.

Here are the steps to extract an email text from Zip archives:

  • Instantiate Parser object for the initial archive;
  • Call GetContainer method and obtain collection of ContainerItem objects;
  • Check if collection isn’t null (container extraction is supported for the document);
  • Iterate through the collection and get container item names, sizes and obtain content.

The following example shows how to extract a text from Zip archives:

// Create an instance of Parser class
using(Parser parser = new Parser(filePath))
{
    // Extract attachments from the container
    IEnumerable<ContainerItem> attachments = parser.GetContainer();

    // Iterate over files
    foreach(ContainerItem item in attachments)
    {
		// Print the file path
		Console.WriteLine(item.FilePath);

        // Print metadata
        foreach(MetadataItem metadata in item.Metadata)
        {
            Console.WriteLine(string.Format("{0}: {1}", metadata.Name, metadata.Value));
        }
       
        try
        {
            // Create Parser object for the file content
            using (Parser fileParser = item.OpenParser())
            {
                // Extract the file text
                using (TextReader reader = fileParser.GetText())
                {
                    Console.WriteLine(reader == null ? "No text" : reader.ReadToEnd());
                }
            }
        }
        catch (UnsupportedDocumentFormatException)
        {
            Console.WriteLine("Isn't supported.");
        }
	}
}

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Document Parser App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to parse documents and extract data from PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Parser App.