How to use System.IO.Compression to read/write ZIP files?

后端 未结 8 1559
灰色年华
灰色年华 2020-12-08 08:13

I know there are libraries out there for working with ZIP files. And, you can alternatively use the functionality built into Windows for working ZIP files.

But, I\'m

相关标签:
8条回答
  • 2020-12-08 08:34

    Since .NET 4.5, Microsoft has offered the ZipArchive class to the System.IO.Compression namespace. Unlike other classes in that namespace, though, like GZipStream and Deflate stream, the ZipArchive requires a reference to the System.IO.Compression.dll assembly.

    It's fairly simple to use, and the link above to MSDN provides some good examples.

    Additionally, Microsoft has created the Microsoft Compression NuGet package, which adds support for ZipArchive and related classes to Windows Phone 8 and other Portable Class Libraries

    0 讨论(0)
  • 2020-12-08 08:35
        public static void zIpDatabseFile(string srcPath, string destPath)
        {//This is for  Zip a File
            using (var source = new FileStream(srcPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            using (var dest = new FileStream(destPath, FileMode.OpenOrCreate, FileAccess.Write))
            using (var zip = new GZipStream(dest, CompressionMode.Compress))
            {
                source.CopyTo(zip);
            }
        }
        public static void uNzIpDatabaseFile(string SrcPath, string DestPath)
        {// This is for unzip a files.
            using (var source = new FileStream(SrcPath, FileMode.Open, FileAccess.Read, FileShare.Read))
            using (var dest = new FileStream(DestPath, FileMode.OpenOrCreate, FileAccess.Write))
            using (var zip = new GZipStream(source, CompressionMode.Decompress))
            {
                zip.CopyTo(dest);
            }
        }
    
    0 讨论(0)
提交回复
热议问题