Back to Devexpress

How to: Archive a Directory

officefileapi-15239-zip-compression-and-archive-api-examples-how-to-archive-a-directory.md

latest1.3 KB
Original Source

How to: Archive a Directory

  • Sep 19, 2023

To archive a directory, do the following:

  1. Create a ZipArchive class instance.
  2. Use its ZipArchive.AddDirectory method to specify the source directory.
  3. Call the ZipArchive.Save method to create an archive and save it to a specified location.

View Example

csharp
using DevExpress.Compression;
        public void ArchiveDirectory() {
            string path = this.startupPath;
            using (ZipArchive archive = new ZipArchive()) {
                archive.AddDirectory(path);
                archive.Save("Documents\\ArchiveDirectory.zip");
            }
        }
vb
Imports DevExpress.Compression
        Public Sub ArchiveDirectory()
            Dim path As String = Me.startupPath
            Using archive As New ZipArchive()
                archive.AddDirectory(path)
                archive.Save("Documents\ArchiveDirectory.zip")
            End Using
        End Sub