C# 如何压缩文件夹和文件?

C# 如何压缩文件夹和文件?,c#,zip,C#,Zip,我想压缩一个文件夹,包括1个文件和1个子文件夹(其中有一些文件) zip.AddDirectory(pathNotesFile,string.Empty); AddFile(pathTempFiles+csvFileName,string.Empty); 我使用了DotNetZip库, 但是在使用了上面的代码之后,我得到的zip文件没有子文件夹 有什么方法可以创建包含子文件夹的zip文件吗?在DotNetZip中,无需调用.AddDirectory()方法即可: 我使用ICSharpCod

我想压缩一个文件夹,包括1个文件和1个子文件夹(其中有一些文件)

zip.AddDirectory(pathNotesFile,string.Empty);
AddFile(pathTempFiles+csvFileName,string.Empty);
我使用了DotNetZip库, 但是在使用了上面的代码之后,我得到的zip文件没有子文件夹


有什么方法可以创建包含子文件夹的zip文件吗?

在DotNetZip中,无需调用.AddDirectory()方法即可:


我使用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);
}

希望这有帮助

您应该添加如何使用
zip
(它是自定义库吗?哪一个?SharpZipLib、DotNetZip等)我不使用您的库。但无论如何,谢谢你的帮助。
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);
}