C#zip解凍し、[content_types] .xmlファイルを回避します



C Zip Decompress Avoid



圧縮および解凍System.IO.Packaging.Packageを使用する場合、自動生成された.xmlファイル[content_types]。

[Content_types] .xmlファイルの構造-VisualStudio | Microsoft Docs



実際、この世代の圧縮は重要ではありませんが、ファイルを抽出するときは、このドキュメントが存在する必要があります。そうでない場合、解凍できません。結局のところ、これはすべてがZip圧縮ファイルをもたらすわけではありません。

どうやるか?



System.IO.Compression.ZipFile

最も簡単な方法は、このクラスで使用するSystem.IO.Compression.ZipFileを使用することです(例)。

/// /// extracting file, this method does not require compressed package [Content_Types] .xml file. /// public static IEnumerable DecompressFileCompatibly(string target, string outPath) { ZipArchive zipArchive = ZipFile.Open(target, ZipArchiveMode.Read) // get all the files (relative path) var files = zipArchive.Entries.Select(e => e.FullName).ToList() // extracting file (requires outPath not exist, must be new) zipArchive.ExtractToDirectory(outPath) // list of files returned, there is no need .xml file [Content_Types]. files.Remove('[Content_Types].xml') // extract out all the final documents var fileList = files.Where(f => { var file = Path.Combine(outPath, f) return File.Exists (file) // filter folder }).Select(f => Path.Combine(outPath, f)).ToList() return fileList }

そうでなければ

次のようなこの問題に対処するサードパーティライブラリを使用することもできます。

SharpZipLib | #ziplibは、.NETプラットフォーム用に完全にC#で記述されたZip、GZip、Tar、およびBZip2ライブラリです。
DotNetZipライブラリ-CodePlexアーカイブ



参照:
.netのZipPackageクラスで[Content_Types] .xmlを回避する方法-スタックオーバーフロー