How can I Compress a directory with .NET?

前端 未结 10 2689
孤街浪徒
孤街浪徒 2021-02-14 16:16

I have a directory that contains several files. I want compress this folder to a zip or tar.gz file. How can I do his work in C#?

10条回答
  •  甜味超标
    2021-02-14 16:27

    i use the System.IO.Packaging Namespace which was introduced with .NET Framework 3.5. I decided to use that one because it's based on .NET Framework Base classes and no 3rd party code is required which blows up the size of the code..

    here's another post on Stackoverflow regarding this Question

    And here's the Namespace and ZipPackage declaration / explanation @MSDN

    hope that helps

    Christian

提交回复
热议问题