[
  {
    "Id": "417744",
    "ThreadId": "204850",
    "Html": "<p>Hi,</p>\r\n<p>how to get file size after adding file to zip, before saving zip?</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\"><br></span></pre>\r\n<pre><span style=\"color:Blue\">using</span> (ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile())\r\n\r\n{\r\n\r\n \t zip.AddProgress += <span style=\"color:Blue\">new</span> EventHandler&lt;AddProgressEventArgs&gt;(zip_AddProgress);\r\n\r\n         zip.AddDirectory(<span style=\"color:#A31515\">@&quot;d:\\test&quot;</span>);\r\n\r\n         zip.Save(<span style=\"color:#A31515\">@&quot;d:\\test.zip&quot;</span>);     \r\n\r\n}\r\n\r\n...\r\n</pre>\r\n</div>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">void</span> zip_AddProgress(<span style=\"color:Blue\">object</span> sender, AddProgressEventArgs e)\r\n{\r\n       totalsize += ????;\r\n}</pre>\r\n<pre>Best regards, Sergey</pre>\r\n</div>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-13T05:55:01.777-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "417784",
    "ThreadId": "204850",
    "Html": "<p>I don't know what you mean by &quot;total size&quot;.</p>\r\n<p>For each entry, there are 2 size quantities, compressed and uncompressed size.&nbsp; These quantities are known as the entries are zipped, not as they are added. In DotNetZip, &quot;add&quot; means the files are added to the list of files to be zipped, upon Save().&nbsp; There's little information collected at the time of Add.&nbsp;</p>\r\n<p>In your own AddProgress evvent handler, you could&nbsp;instantiate a FileInfo() for each file being added, and compute the aggregate uncompressed size of all entries being added.&nbsp; This works only if all entries are filesystem files. It's possible that some entries are streams, in which case you won't know the size of the uncompressed entry until you read the stream all the way through.</p>\r\n<p>Within a SaveProgress event handler, your application&nbsp;can get the total bytes to read (on-disk size of the file) and the total bytes read so far.&nbsp; After each entry has been completely compressed, the SaveProgress event fires again, and at that point you can get the compressed size of the entry.&nbsp;</p>\r\n<p>There's no way to know the total size of the zip file until after compression completes.</p>\r\n<p>Check the documentation for the SaveProgress event for an illustration of how to do it.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-13T10:48:14.92-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "417793",
    "ThreadId": "204850",
    "Html": "<p>Cheeso, thanks.</p>\r\n<p>I tried to make 2 progress bars: first - file progress, second - total progress. For total progress bar i want to set maximum value - total size of all files, than in SaveProgress event i update total progress bar. FileInfo class give me file length, but i need &quot;size on disk&quot; to update progress bar correct. I find how to calculate it next way: &quot;diskSize = 4096 * ((fileInfo.Length + 4096 - 1)/ 4096)&quot; where 4096 - is clusterSize for ntfs file system.</p>\r\n<p>Thanks for help, i will use AddProgress event and FileInfo class.</p>",
    "PostedDate": "2010-03-13T12:23:41.87-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "418135",
    "ThreadId": "204850",
    "Html": "<p>Ah, yes - ok, what you describe makes sense.</p>\r\n<p>In SaveProgressEventArgs, there is a TotalBytesToTransfer property.&nbsp; It refers to only the current&nbsp;entry, though.&nbsp; What you're doing is counting the bytes for all entries.</p>\r\n<p>I'm not sure why you are fiddling with the cluster size. That ought to be a detail you can ignore.&nbsp; FileInfo.Length should give you what you want, without elaboration.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-15T03:09:37.82-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]