How to list archive folders

Listing 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(""))
                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

GitHub Examples

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

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.