Dzun Ho
Dzun Ho

Reputation: 367

How to zip a folder and a file?

I want to zip a folder include 1 file and 1 sub folder (have some file in it).

enter image description here

zip.AddDirectory(pathNotesFile, string.Empty);
zip.AddFile(pathTempFiles + csvFileName, string.Empty);

I have use DotNetZip library, But after use these code above, the zip file which I get didn't have a sub folder.

enter image description here

Is there any way to create a zip file with a subfoler in it???

Upvotes: 2

Views: 121

Answers (2)

Bartek Falkowski
Bartek Falkowski

Reputation: 67

In DotNetZip you can do it without calling .AddDirectory() method :

zip.AddFile(pathTempFiles + csvFileName, directoryPathInArchive: "Attachments");

Upvotes: 2

coder3521
coder3521

Reputation: 2646

I use ICSharpCode.SharpZipLib

public static void ZipPath(string zipFilePath, string sourceDir, string pattern, bool withSubdirs, string password)
{
    FastZip fz = new FastZip();
    if (password != null)
        fz.Password = password;

    fz.CreateZip(zipFilePath, sourceDir, withSubdirs, pattern);
}

hope this helps

Upvotes: 0

Related Questions