[
  {
    "Id": "187527",
    "ThreadId": "55534",
    "Html": "Hello,<br>\r\n<br>\r\nI've tried searching for examples of how to do this, but haven't found them if they are already out there.<br>\r\n<br>\r\nI'm trying to write a bit of code for a web-app (C#) that essentially takes a dataset and create a zip file.&nbsp; The zip file should contain a csv file for each datatable in the dataset.&nbsp; Each csv file should be relatively small in size and the file count could range from 2-10 files.&nbsp; I can get each datatable into a csv format (either by string or stream).&nbsp; From what I've read, it seems that DetNetZip should be able to handle this, but I'm clueless how to set this up.<br>\r\n<br>\r\nMy goal is to avoid writing anything to disc on the web-server and have the client's browser ask what to do with the zip-file that was just downloaded after an &quot;Export&quot; button was clicked.<br>\r\n<br>\r\nAny insight would be greatly appriciated!<br>\r\n<br>\r\n~ Ben \r\n",
    "PostedDate": "2009-05-06T16:40:56.107-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "187768",
    "ThreadId": "55534",
    "Html": "Sorry to waste time here - a continual call of .AddFileFromString worked!<br>\r\n<br>\r\n&nbsp;&nbsp;&nbsp; private void ExportData(List&lt;int&gt; tables)<br>\r\n&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Clear();<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = &quot;application/zip&quot;;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.AddHeader(&quot;content-disposition&quot;, &quot;filename=&quot; + string.Format(&quot;archive-{0}.zip&quot;, DateTime.Now.ToString(&quot;yyyy-MMM-dd-HHmm&quot;)));<br>\r\n<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using (ZipFile zip = new ZipFile())<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp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;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddFileFromString(&quot;blah-2.csv&quot;, &quot;&quot;, ConvertTableToString(index));<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case 3:<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.AddFileFromString(&quot;blah-3.csv&quot;, &quot;&quot;, ConvertTableToString(index));<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Save(Response.OutputStream);<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<br>\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.End();<br>\r\n&nbsp;&nbsp;&nbsp; }<br>\r\n<br>\r\n&nbsp;&nbsp;&nbsp; private string ConvertTableToString(int datasetIndex)<br>\r\n&nbsp;&nbsp;&nbsp; {<br>\r\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// fun mapping code<br>\r\n&nbsp;&nbsp;&nbsp; }<br>\r\n",
    "PostedDate": "2009-05-07T08:58:31.853-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "187826",
    "ThreadId": "55534",
    "Html": "Glad you found something that works for you. <br>\r\nThere is also AddFileFromStream() which works similarly, but with a stream. a MemoryStream might be interesting in your scenario. <br>\r\nWith this latter method you can provide the stream on a just-in-time basis. Check the docs if you are interested. <br>\r\n<br>\r\nWhat you are doing will work just fine with a few entries in the zip, and a smallish zip file.  As zip files become larger and there are more files, the advantage of using just-in-time streams becomes real.  Imagine a zip file with 10,000 csv entries.  With AddFileFromString(), all that data has to be kept in memory.  With AddFileFromStream, you keep only the data for a single entry in memory at one time.<br>\r\n<br>\r\nThinking about it, I may be able to modify the library to provide the just-in-time capability with the AddFileFromString() method.  But no one has asked for that, yet.<br>\r\n<br>\r\n<br>\r\n",
    "PostedDate": "2009-05-07T11:58:07.967-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]