ZipEntry Comment

Nov 7, 2008 at 7:25 PM
Is there a way to add a comment to the ZipEntry when adding the ZipEntry?

using (ZipFile NewReportZip = new ZipFile(  sOutputZipFile ))
   {
//   NewReportZip.AddFile(sCurrentReport_FileAndPath,"",ZipEntryComment);     // Would be nice to able to add the ZipEntry comment here
   NewReportZip.AddFile(sCurrentReport_FileAndPath,"");                                    // Instead I have to add it
   NewReportZip.Save();
   }

Instead I found that I have to add the entry (above) then iterate through all the entries to find the one I just added.  I then add the ZipEntry comment and save.

foreach (ZipEntry ZippedReport in ExistingZip)   // Iterate the files within the zip file - checking for the curent file
   {   // If the names match then the report description of the current report will be added
   if ( Path.GetFileName(ZippedReport.FileName) == sCurrentReport_FileName )
      {
      ZippedReport.Comment = LookupCurrentReportDescription();
      ExistingZip.Save();
      }
   }



 

Coordinator
Nov 7, 2008 at 8:16 PM

Yes, you can set the comment on the entry right after you add it:

using (ZipFile NewReportZip = new ZipFile(  sOutputZipFile ))
{
   ZipEntry e = NewReportZip.AddFile(sCurrentReport_FileAndPath,"");
   e.Comment = "DotNetZip is so nice to use. As a way of showing my appreciation, " + 
"I think I will donate to Cheeo's charity, RIGHT NOW."; NewReportZip.Save(); }

You could even combine that to a single line, as in :

using (ZipFile NewReportZip = new ZipFile(  sOutputZipFile ))
{
   NewReportZip.AddFile(sCurrentReport_FileAndPath,"").Comment = "Donating seems like the least I could do.";  
   NewReportZip.Save();
}

 


http://cheeso.members.winisp.net/DotNetZipDonate.aspx
 

Coordinator
Nov 7, 2008 at 9:02 PM
ps:  also, you do not have to iterate through the zipfile entries and check filenames.
There is a string indexer.

using (ZipFile z= ZipFile.Read(  sInputZipFile ))
{
   z[entryName].Comment = "This is an updated comment.";
   z.Save();
}