2010-07-06 54 views
1
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#作爲語言,但這顯示爲錯誤)。請幫助。使用dotnetzip列出文件

+0

header是一個布爾值。你的錯誤是什麼? – 2010-07-06 11:51:49

+0

它無法識別標題(它強調紅色標註「名稱標題」在當前上下文中不存在)。 – 2010-07-06 11:54:56

+0

我實際上是http://dotnetzip.codeplex.com/wikipage?title=CS-Examples&referringTitle中的代碼= Examples – 2010-07-06 11:56:55

回答

4

看完你的評論後,我會說你需要聲明和初始化頭變量。類似這樣的:

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