How can I Compress a directory with .NET?

前端 未结 10 2718
孤街浪徒
孤街浪徒 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:46

    GZip is part of Microsoft Framework 2.0 onward. Its called GZipStream under System.IO.Compression namespace.

    To compress a directory with this class, you'd have to create a serializable class (for e.g. Directory) which contains a collection of Files.

    The Files class would contain file-name and file-stream to read bytes from file. Once you do apply GZip on the Directory, it'll read Files one by one and write them to GZipStream.

    Check this link: http://www.vwd-cms.com/forum/forums.aspx?topic=18

提交回复
热议问题