使用c#.net创建文件夹的zip文件 [英] create zip file of a folder using c#.net

查看:141
本文介绍了使用c#.net创建文件夹的zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我如何使用c#.net创建文件夹的zip文件(包含多个子文件夹)。

是否有任何内置程序集在dot net或其他?

Can any one give me idea about how to create a zip file of a folder(contain multiple sub folders)using c#.net.
Is there any inbuilt assembly in dot net or any other?

推荐答案

1。不要大喊大叫!

2.我使用的ICSharpCode.SharpZipLib可以免费下载,也可以用于商业应用。

代码看起来像这样:

1. DON''T SHOUT!
2. I use ICSharpCode.SharpZipLib which can be freely downloaded and also used in commercial applications.
Code looks like that:
foreach (string folderToZip in foldersToZip)
{
    if (!string.IsNullOrWhiteSpace(folderToZip) && Directory.Exists(folderToZip))
    {
        string targetFile = Path.Combine(targetFolder, Path.GetFileName(folderToZip) + ".zip");
        ZipPath(targetFile, folderToZip, null, true, null);
    }
}






and

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);
}


您好b $ b

您可以下载这个ICSharpCode.SharpZipLib.dll。



Hi
You can download this ICSharpCode.SharpZipLib.dll.

FastZip fz = new FastZip();
fz.ExtractZip(Pass Path here);


以上解决方案很好,但仍然有一些疑问。



我们找到了一个更好的解决方案,使用带有c#,vb.net的asp.net压缩和解压缩文件和文件夹。

我们还解决了产生两个问题的问题我们解压缩任何文件夹时的文件夹。



我们希望本文可以更好地帮助您。你也可以从这个链接下载源代码,dll。



DotNetZip - 在C#,VB,任何.NET语言中压缩和解压缩< br $>




问候 -

Dotnet开发者对开发者组织
Above solution is Good but still have some doubts in it.

we have find a better solution to zip and unzip files and folders using asp.net with c#, vb.net.
and we also fixed the problem which creates two folder when we unzip any folder.

we hope this article may help you in better way. you can also download source code, dll from this link.

DotNetZip – Zip and Unzip in C#, VB, any .NET language


Regards-
Dotnet Developers to Developers Group


这篇关于使用c#.net创建文件夹的zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆