How to list archive folders

GroupDocs.Viewer provides additional information such as list of folders when calling GetViewInfo method. To retrieve view information for Archive File call GetViewInfo method and cast output result to ArchiveViewInfo type.

Following example demonstrates how to print out archive contents.

public static void PrintViewInfo()
{
    using (Viewer viewer = new Viewer("sample.zip"))
    {
        ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForHtmlView();
        ViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions);

        Console.WriteLine("File type: " + viewInfo.FileType);
        Console.WriteLine("Pages count: " + viewInfo.Pages.Count);
        Console.WriteLine("Folders: ");
        Console.WriteLine(" - /");

        string rootFolder = string.Empty;
        PrintFolders(viewer, rootFolder);
    }
}

private static void PrintFolders(Viewer viewer, string folder)
{
    ViewInfoOptions viewInfoOptions = ViewInfoOptions.ForHtmlView();
    viewInfoOptions.ArchiveOptions.Folder = folder;

    ArchiveViewInfo viewInfo = viewer.GetViewInfo(viewInfoOptions) as ArchiveViewInfo;

    foreach (string subFolder in viewInfo.Folders)
    {
        Console.WriteLine($" - {subFolder}");
        PrintFolders(viewer, subFolder);
    }
}

More resources

View Archive Files Online

Along with full-featured .NET library we provide simple but powerful free online Apps. View ZIP and TAR files online with GroupDocs Viewer App.

GitHub Examples

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