使用dotnetzip列出文件

时间:2010-07-06 11:40:33

标签: c# dotnetzip

using (ZipFile zip = ZipFile.Read(ExistingZipFile))  
  {  
    foreach (ZipEntry e in zip)  
    {  
      if (header)  
      {  
        System.Console.WriteLine("Zipfile: {0}", zip.Name);  
        if ((zip.Comment != null) && (zip.Comment != ""))   
          System.Console.WriteLine("Comment: {0}", zip.Comment);  
        System.Console.WriteLine("\n{1,-22} {2,8}  {3,5}   {4,8}  {5,3} {0}",  
                                 "Filename", "Modified", "Size", "Ratio", "Packed", "pw?");  
        System.Console.WriteLine(new System.String('-', 72));  
        header = false;  
      }  
      System.Console.WriteLine("{1,-22} {2,8} {3,5:F0}%   {4,8}  {5,3} {0}",  
                               e.FileName,  
                               e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"),  
                               e.UncompressedSize,  
                               e.CompressionRatio,  
                               e.CompressedSize,  
                               (e.UsesEncryption) ? "Y" : "N");  

    }  
  }  

我正在使用上面的代码来打印zip文件中的苍蝇列表。有人告诉我这里的标题是什么。(我在asp.net代码中使用c#作为语言写这个,但这显示为错误)。请帮忙。

1 个答案:

答案 0 :(得分:4)

阅读完评论后,我会说你需要声明并初始化标题变量。像这样:

using (ZipFile zip = ZipFile.Read(ExistingZipFile))  
  {  
    bool header = true;
    foreach (ZipEntry e in zip)  
    {  
      if (header)  
...
相关问题