Using SharpZipLib to unzip specific files?

后端 未结 4 1004
你的背包
你的背包 2020-12-04 21:57

I\'m trying to use SharpZipLib to pull specified files from a zip archive. All of the examples I\'ve seen always expect that you want to unzip the entire zip, and do somethi

4条回答
  •  甜味超标
    2020-12-04 22:07

    ZipFile.GetEntry should do the trick:

    using (var fs = new FileStream(sourcePath, FileMode.Open, FileAccess.Read))
    using (var zf = new ZipFile(fs)) {
       var ze = zf.GetEntry(fileName);
       if (ze == null) {
          throw new ArgumentException(fileName, "not found in Zip");
       }
    
       using (var s = zf.GetInputStream(ze)) {
          // do something with ZipInputStream
       }
    }
    

提交回复
热议问题