C# ZipFile CreateFromDirectory(String, String)

Description

ZipFile CreateFromDirectory(String, String) Creates a zip archive that contains the files and directories from the specified directory.

Syntax

ZipFile.CreateFromDirectory(String, String) has the following syntax.


public static void CreateFromDirectory(
  string sourceDirectoryName,
  string destinationArchiveFileName
)

Parameters

ZipFile.CreateFromDirectory(String, String) has the following parameters.

  • sourceDirectoryName - The path to the directory to be archived, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.
  • destinationArchiveFileName - The path of the archive to be created, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.

Returns

ZipFile.CreateFromDirectory(String, String) method returns

Example

This example shows how to create and extract a zip archive by using the ZipFile class.


/*w  ww  . j a v  a  2 s.c  o  m*/

using System;
using System.IO;
using System.IO.Compression;

class Program
{
    static void Main(string[] args)
    {
        string startPath = @"c:\example\start";
        string zipPath = @"c:\example\result.zip";
        string extractPath = @"c:\example\extract";

        ZipFile.CreateFromDirectory(startPath, zipPath);

        ZipFile.ExtractToDirectory(zipPath, extractPath);
    }
}




















Home »
  C# Tutorial »
    System.IO.Compression »




DeflateStream
GZipStream
ZipArchive
ZipArchiveEntry
ZipFile
ZipFileExtensions