Working with ZIP archives

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.Metadata MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-metadata -- dnx GroupDocs.Metadata.Mcp --yes
Folders, licensing and more →

Get ZIP format metadata

The API allows detecting ZIP archives and reading format metadata. The following steps are needed to be followed:

  • Load a ZIP archive
  • Get the root metadata package
  • Extract  the native metadata package using ZipRootPackage.ZipPackage
  • Read the ZIP archive properties
  • Loop through ZipPackage.Files to extract information about archived files 

The following code snippet shows how to get metadata from a ZIP archive.

AdvancedUsage.ManagingMetadataForSpecificFormats.Archive.ZipReadNativeMetadataProperties

Encoding encoding = Encoding.GetEncoding(866);
using (Metadata metadata = new Metadata(Constants.InputZip))
{
	var root = metadata.GetRootPackage<ZipRootPackage>();

	Console.WriteLine(root.ZipPackage.Comment);
	Console.WriteLine(root.ZipPackage.TotalEntries);

	foreach (var file in root.ZipPackage.Files)
	{
		Console.WriteLine(file.Name);
		Console.WriteLine(file.CompressedSize);
		Console.WriteLine(file.CompressionMethod);
		Console.WriteLine(file.Flags);
		Console.WriteLine(file.ModificationDateTime);
		Console.WriteLine(file.UncompressedSize);

		// Use a specific encoding for the file names
		Console.WriteLine(encoding.GetString(file.RawName));
	}
}

Updating the user comment

GroupDocs.Metadata for .NET allows you to update the user comment in a ZIP archive. The following steps are needed to be followed:

  • Load a ZIP archive
  • Get the root metadata package
  • Update the comment using the ZipPackage.Comment setter
  • Save the changes

The following code snippet demonstrates the usage of this feature.

AdvancedUsage.ManagingMetadataForSpecificFormats.Archive.ZipUpdateArchiveComment

using (Metadata metadata = new Metadata(Constants.InputZip))
{
	var root = metadata.GetRootPackage<ZipRootPackage>();
	root.ZipPackage.Comment = "updated comment";

	metadata.Save(Constants.OutputZip);
}

Removing the user comment

GroupDocs.Metadata for .NET allows you to remove the user comment associated with a ZIP archive. The following code snippet demonstrates the usage of this feature.

AdvancedUsage.ManagingMetadataForSpecificFormats.Archive.ZipRemoveArchiveComment

using (Metadata metadata = new Metadata(Constants.InputZip))
{
	var root = metadata.GetRootPackage<ZipRootPackage>();
	root.ZipPackage.Comment = null;

	metadata.Save(Constants.OutputZip);
}

More resources

GitHub examples

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

Free online document metadata management App

Along with full featured .NET library we provide simple, but powerful free Apps. You are welcome to view and edit metadata of PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, emails, images and more with our free online Free Online Document Metadata Viewing and Editing App.