Extract FileGDB Content from ZIP in .NET

Use Aspose.ZIP for .NET to inspect a ZIP archive and restore a complete FileGDB dataset required by a C# application. An Esri file geodatabase is a directory containing multiple related files, not one standalone asset. Extraction therefore means locating a folder whose name ends in .gdb, recreating its validated directory structure, and writing every member needed by the dataset.

Selective extraction fits GIS imports, mapping services, field-data synchronization, spatial ETL, and geodata delivery. The application can skip unrelated entries, enforce output and resource policies, and pass approved files to the next service without expanding the complete archive.

How to Extract FileGDB Files from ZIP Using C#

Install the Aspose.ZIP package for .NET and import the Aspose.Zip namespace. Archive metadata is available before anything is written, allowing the application to evaluate ArchiveEntry.Name, ArchiveEntry.IsDirectory, and ArchiveEntry.UncompressedSize as part of its acceptance policy.


Package Manager Console Command

PM> Install-Package Aspose.Zip

Open the ZIP with Archive, enumerate Archive.Entries, identify the .gdb/ directory boundary and restore all entries below it, and call ArchiveEntry.Extract for each approved destination. Because FileGDB is directory-based, the sample preserves validated relative paths and verifies that every resolved destination remains below the output root.

Steps to Restore FileGDB Files in C#

  • Resolve the source ZIP path and create an isolated output directory.
  • Open the package with the Archive class.
  • Enumerate Archive.Entries instead of expanding every item.
  • Identify entries stored below a directory whose name ends in .gdb.
  • Build a destination path that remains under the approved output root.
  • Reject entries that exceed the configured expanded-size limit.
  • Save each accepted item with ArchiveEntry.Extract.

System Requirements

Before running the example, make sure the environment includes:

  • A supported .NET runtime on Windows, Linux, or macOS.
  • Visual Studio, JetBrains Rider, Visual Studio Code, or another C# development environment.
  • Aspose.ZIP for .NET installed through NuGet or referenced as an assembly.
  • Read access to the source archive and write access to the destination directory.
  • Storage and execution limits appropriate for untrusted compressed input.

C# Example: Select FileGDB Files in a ZIP Archive

A file geodatabase is a directory, so the code keeps the validated relative paths of every entry below a folder whose name ends in .gdb. It creates required subdirectories and rejects any resolved path outside the approved destination. Production code should also define a deterministic policy for duplicate output names.

Extract FileGDB Files from ZIP - C#

using Aspose.Zip;
using System;
using System.IO;

string archivePath = Path.GetFullPath("geodata.zip");
string outputDirectory = Path.GetFullPath("extracted-filegdb");
const ulong MaxEntrySize = 100UL * 1024 * 1024;

Directory.CreateDirectory(outputDirectory);

using (var archive = new Archive(archivePath))
{
    foreach (ArchiveEntry entry in archive.Entries)
    {
        string normalizedName = entry.Name.Replace('\\', '/');
        int marker = normalizedName.IndexOf(".gdb/", StringComparison.OrdinalIgnoreCase);
        if (marker < 0) continue;

        string relativePath = normalizedName;
        string destinationPath = Path.GetFullPath(
            Path.Combine(outputDirectory, relativePath.Replace('/', Path.DirectorySeparatorChar)));
        string pathFromRoot = Path.GetRelativePath(outputDirectory, destinationPath);

        if (Path.IsPathRooted(pathFromRoot)
            || pathFromRoot.Equals("..", StringComparison.Ordinal)
            || pathFromRoot.StartsWith(
                ".." + Path.DirectorySeparatorChar,
                StringComparison.Ordinal))
        {
            throw new InvalidDataException("Archive entry resolves outside the output directory.");
        }

        if (entry.IsDirectory)
        {
            Directory.CreateDirectory(destinationPath);
            continue;
        }

        if (entry.UncompressedSize > MaxEntrySize)
        {
            throw new InvalidDataException(
                $"Entry '{entry.Name}' exceeds the 100 MB extraction limit.");
        }

        Directory.CreateDirectory(Path.GetDirectoryName(destinationPath)!);
        entry.Extract(destinationPath);
    }
}

Implementation Notes for FileGDB Packages

Unlike a single-file asset, a file geodatabase must retain its internal directory structure. Extracting only one member can leave the dataset unusable.

The restored file still requires geospatial validation. Check its coordinate reference information, schema, companion resources, and geometry with the GIS component used by the application.

The example preserves the geodatabase directory tree because flattening it would destroy the dataset structure. If the archive contains more than one .gdb root or repeated entry names, reject the ambiguous package or route each dataset to a separate validated destination.

Security and Privacy Considerations

Treat archive names and payloads as untrusted. Never append ArchiveEntry.Name directly to the destination path because absolute paths and parent-directory segments can write outside the intended folder. The FileGDB example resolves each destination with Path.GetFullPath and rejects rooted or parent-relative results returned by Path.GetRelativePath.

Set limits for compressed input size, per-entry and total expanded size, entry count, processing time, and concurrent jobs. Extract into restricted temporary storage, clean up partial output after failures, scan files when the application requires it, and avoid logging private filenames or document contents.

FileGDB Extraction FAQ

How do I extract only FileGDB files from a ZIP archive in C#?

Open the ZIP with Archive, find entries below a directory whose name ends in .gdb, validate each resolved path, and extract the complete directory tree.

Does Aspose.ZIP validate the content of an extracted FileGDB file?

No. FileGDB is a directory-based dataset. Preserve all files below the .gdb folder and validate the complete restored geodatabase with a GIS component.

Can the same selection pattern be used with 7Z, RAR, or TAR containers?

Yes, but open each container with its corresponding Aspose.ZIP archive class. Entry types and available extraction methods can differ by archive format.

How should duplicate FileGDB filenames be handled?

Choose the rule before extraction: reject duplicates, generate unique names, or preserve a validated relative directory structure.