2010-07-03 117 views
5

如何查找zip文件中的文件列表,而無需在c#中解壓縮。內部zip文件內容

+0

可能重複?](http://stackoverflow.com/questions/940582/how-do-i-zip-a-file-in-c-using-no-3rd-party-apis) – egrunin 2010-07-03 18:55:03

回答

8

隨着sharpziplib

ZipInputStream zip = new ZipInputStream(File.OpenRead(path)); 
ZipEntry item; 
while ((item = zip.GetNextEntry()) != null) 
{ 
    Console.WriteLine(item.Name); 
} 
+0

是否有可能沒有sharpziplib。 – 2010-07-03 07:39:21

+0

@Niraj Choubey:是的,與其他一些ZIP庫(如http://dotnetzip.codeplex.com/).....或者您必須自己重新創建整個ZIP代碼才能查看ZIP文件。 ... – 2010-07-03 07:55:24

+0

也許'System.IO'將在.NET框架的未來版本中本地支持ZIP歸檔 - 請參閱http://blogs.msdn.com/b/bclteam/archive/2010/06/28/working -with-拉鍊文件正在net.aspx – 2010-07-04 07:19:25

1

有一個簡單的方法與sharpziplib做到這一點:

 using (var zipFile = new ZipFile(@"C:\Test.zip")) 
     { 
      foreach (ZipEntry entry in zipFile) 
      { 
       Console.WriteLine(entry.Name); 
      } 
     } 
的[我如何ZIP在C#中的文件,不使用第三方的API