[
  {
    "Id": "416881",
    "ThreadId": "204625",
    "Html": "<p>hi, experts! I am a newbie to handle the files in C#.</p>\r\n<p>I use this library v1.9 on asp.net</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre>\r\n        <span style=\"color:Blue\">protected</span> <span style=\"color:Blue\">void</span> btnDownload2_Click(<span style=\"color:Blue\">object</span> sender, EventArgs e)\r\n        {\r\n\r\n            Response.Clear();\r\n\r\n            System.Web.HttpContext c = System.Web.HttpContext.Current;\r\n\r\n            Response.ContentType = <span style=\"color:#A31515\">&quot;application/zip&quot;</span>;\r\n            Response.AddHeader(<span style=\"color:#A31515\">&quot;content-disposition&quot;</span>, <span style=\"color:#A31515\">&quot;filename=&quot;</span> + <span style=\"color:#A31515\">&quot;download.zip&quot;</span>);\r\n\r\n            ZipFile zip = <span style=\"color:Blue\">new</span> ZipFile(<span style=\"color:#A31515\">&quot;download.zip&quot;</span>);\r\n\r\n            FileStream fs = <span style=\"color:Blue\">null</span>;\r\n            <span style=\"color:Blue\">byte</span>[] data = <span style=\"color:Blue\">null</span>;\r\n            <span style=\"color:Blue\">int</span> length = 0;\r\n\r\n            <span style=\"color:Blue\">for</span> (<span style=\"color:Blue\">int</span> i = 0; i &lt;= 9; i++)\r\n            {\r\n                fs = <span style=\"color:Blue\">new</span> FileStream(<span style=\"color:#A31515\">&quot;C:\\\\test_dotnetzip_files\\\\&quot; + i.ToString() + &quot;</span>.bak&quot;, FileMode.Open);\r\n                length = Convert.ToInt32(fs.Length);\r\n                data = <span style=\"color:Blue\">new</span> <span style=\"color:Blue\">byte</span>[length];\r\n                fs.Read(data, 0, length);\r\n                fs.Close();\r\n\r\n                zip.AddEntry(<span style=\"color:#A31515\">&quot;a\\\\&quot; + i.ToString() + &quot;</span>.bak&quot;, data);    \r\n            }\r\n\r\n            zip.Save(Response.OutputStream);\r\n            Response.End();\r\n\r\n        }\r\n</pre>\r\n<pre><span style=\"color:#000000\">in the above code, I use filestream and byte[] to add entry to the zipfile.</span></pre>\r\n<pre><span style=\"color:#000000\">I found that byte[] uses memory, </span></pre>\r\n<pre><span style=\"color:#000000\">when the size of files are too large, it is so easy to make OutOfMemoryException occur.</span></pre>\r\n<pre><span style=\"color:#000000\">how to handle this case when using DotNetZip?</span></pre>\r\n<pre><span style=\"color:#000000\">Thank you very much!</span></pre>\r\n</div>",
    "PostedDate": "2010-03-11T03:00:19.457-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "416932",
    "ThreadId": "204625",
    "Html": "<p>You are reading the entire contents of ALL of the files into memory, before putting them into the zip file.&nbsp; Why not use the AddFile method?</p>\r\n<pre>for (int i = 0; i &lt;= 9; i++)\r\n{\r\n    var filename = &quot;C:\\\\test_dotnetzip_files\\\\&quot; + i.ToString() + &quot;.bak&quot;;\r\n    zip.AddFile(filename, &quot;a&quot;);    \r\n}\r\n\r\n</pre>",
    "PostedDate": "2010-03-11T05:40:54.043-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "416940",
    "ThreadId": "204625",
    "Html": "<p>Dear <a id=\"ctl00_ctl00_MasterContent_Content_PostRepeater_ctl02_UserNameLink\" href=\"http://www.codeplex.com/site/users/view/Cheeso\">Cheeso</a>,</p>\r\n<p>Hi, actually the files are store in the sql server as varbinary (data type).</p>\r\n<p>the file are loaded and stored as byte[] at code behind.</p>\r\n<p>are there any better ways?</p>\r\n<p>Thank you very much!</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-11T05:54:08.427-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "416941",
    "ThreadId": "204625",
    "Html": "<table border=0 width=800>\r\n<tbody>\r\n<tr>\r\n<td>\r\n<p>Yes, use AddEntry, with a WriteDelegate.&nbsp; Inside your WriteDelegate, open a stream to the Sql Server and write it, in chunks (not all at once) to the zip archive.&nbsp; Or, use the overload of AddEntry() that accepts an OpenDelegate and CloseDelegate.&nbsp;For that one, you need only to open the &nbsp;stream in the opener, and close the stream in the closer, and DotNetZip writes the content from the stream in chunks into the zip file.&nbsp;</p>\r\n<p>The documentation has examples of these.</p>\r\n<p>&nbsp;</p>\r\n</td>\r\n</tr>\r\n</tbody>\r\n</table>",
    "PostedDate": "2010-03-11T05:58:04.78-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "416946",
    "ThreadId": "204625",
    "Html": "<p>the file size of each file may be 100 MB.</p>\r\n<p>And there will be several big files to archive as&nbsp;one .zip file.</p>\r\n<p>Thank you very much! let me test!</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-03-11T06:13:30.597-08:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]