c# - 使用 dotnetzip 列出文件

标签 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# 作为语言编写这个,但这显示为错误)。请帮忙。

最佳答案

阅读您的评论后,我会说您需要声明并初始化 header 变量。像这样:

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

关于c# - 使用 dotnetzip 列出文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3185845/

相关文章:

asp.net-mvc - 在 MVC 中使用内存流和 DotNetZip 给出 "Cannot access a closed Stream"

C# WPF 使用 DotNetZip 检测提取完成?

c# - 将 Json 转换为字符串数组

c# - 根据更改集编号从 TFS 下载文件

c# - 我可以在 Visual C# 中向后浏览文本以查找字符串吗?

c# - 通过 C# redis 客户端连接到 redis 很慢!

c# - 通过网络将压缩数据从 C# 发送到 Java

c# - 纯粹在 xaml 中连接文字和静态资源字符串

c# 寻找 API 来读取 7z header

c# - 从 dotnetzip 创建的 zip 文件中提取时出错 - "Windows cannot complete the extraction."