[
  {
    "Id": "187997",
    "ThreadId": "55666",
    "Html": "<p>I have seen the examples on how to compress memorysteam (string variable) items into a zipfile and was able to successfully do this.</p>\r\n<p>I now want to decompress them back into the memorystream (string variables) from the zip file. Is this possible? Can someone show me an example of how to do this please. I couldn't find any information regarding this.</p>\r\n<p>Thanks</p>",
    "PostedDate": "2009-05-07T23:46:10.83-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "188120",
    "ThreadId": "55666",
    "Html": "<p>I was able to decompress the files into memory like so:</p>\r\n<pre><strong id=1>1    </strong>  MemoryStream ms = <span>new</span> MemoryStream();<br><strong id=2>2    </strong>  <span>using</span> (ZipFile zip = ZipFile.Read(ZipFileToRead))<br><strong id=3>3    </strong>  {<br><strong id=4>4    </strong>    zip[<span>&quot;DataFile.csv&quot;</span>].Extract(ms);<br><strong id=5>5    </strong>  }<br><strong id=6>6    </strong><br><br>but I want to tweak my question a little bit.<br><br>Say I have a folder in the zip file containing many different files (unknown number), how can I decompress the file into a List&lt;&gt; of say string with each index having each different zip file?</pre>",
    "PostedDate": "2009-05-08T06:44:57.253-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "188122",
    "ThreadId": "55666",
    "Html": "<p>I think you are mixing things.</p>\r\n<p>There are a couple of related methods.&nbsp; One is ZipFile.AddFileFromString() and the other, AddFileFromStream().&nbsp; They are two distinct methods.&nbsp; If you want to create an entry in a zip file, using the contents of a string, then use the former.&nbsp; If you want to use the contents of a stream (including a MemoryStream), use the latter.&nbsp;&nbsp; In each case the result is a zipfile with an entry.</p>\r\n<p>I think you are asking about extracting an entry to a stream, or perhaps to a string.&nbsp; In the extraction case, there is no ExtractToString() method, so you must extract to a stream, using the&nbsp;ZipEntry.Extract(Stream) method, and a MemoryStream.&nbsp; Example:&nbsp;</p>\r\n<pre>            <span style=\"color:#a020f0\">using</span> (<span style=\"color:#228b22\">ZipFile</span> <span style=\"color:#b8860b\">zip</span> = <span style=\"color:#5f9ea0\">ZipFile</span>.Read(_zipFileName))\r\n            {\r\n                <span style=\"color:#228b22\">var</span> <span style=\"color:#b8860b\">r</span> = zip[<span style=\"color:#bc8f8f\">&quot;files/Readme.txt&quot;</span>];\r\n                <span style=\"color:#a020f0\">if</span> (r!= <span style=\"color:#5f9ea0\">null</span>)\r\n                {\r\n                    <span style=\"color:#a020f0\">using</span> (<span style=\"color:#228b22\">var</span> <span style=\"color:#b8860b\">ms</span> = <span style=\"color:#a020f0\">new</span> MemoryStream())\r\n                    {\r\n                        <span style=\"color:#5f9ea0\">r</span>.Extract(ms);\r\n\r\n                        <span style=\"color:#228b22\">byte</span>[] <span style=\"color:#b8860b\">block</span> = <span style=\"color:#5f9ea0\">ms</span>.ToArray();\r\n                        <span style=\"color:#228b22\">string</span> <span style=\"color:#b8860b\">readmeString</span> = <span style=\"color:#5f9ea0\">System</span>.<span style=\"color:#5f9ea0\">Text</span>.<span style=\"color:#5f9ea0\">Encoding</span>.Default.GetString(block, 0, <span style=\"color:#5f9ea0\">block</span>.Length);\r\n                        <span style=\"color:#5f9ea0\">Console</span>.WriteLine(<span style=\"color:#bc8f8f\">&quot;README: {0}\\n\\nPress &lt;ENTER&gt; to continue...\\n&quot;</span>, readmeString);\r\n                        <span style=\"color:#5f9ea0\">Console</span>.ReadLine();\r\n                    }\r\n                }\r\n            }\r\n</pre>\r\n<hr>\r\n<p>The code above retrieves an entry by name.&nbsp; The entry name is &quot;files/Readme.txt&quot; - in other words, in the zip file, there is a Readme.txt file, stored in the &quot;files&quot; directory.&nbsp; That entry is extracted to a MemoryStream, which is then decoded into a string.&nbsp; The text encoding used here, for extraction,&nbsp;is System.Text.Encoding.Default.&nbsp; But you can use any encoding, just ensure that you use the same encoding for extraction that was used for storage.&nbsp; [FYI: When you use AddFileFromString, DotNetZip encodes the string using the Default encoding]</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-05-08T06:45:46.51-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "188127",
    "ThreadId": "55666",
    "Html": "<p>our replies crossed.</p>\r\n<p>To answer your 2nd Q, something like this might work:</p>\r\n<pre>            <span style=\"color:#228b22\">var</span> <span style=\"color:#b8860b\">list</span> = <span style=\"color:#a020f0\">new</span> <span style=\"color:#5f9ea0\">System</span>.<span style=\"color:#5f9ea0\">Collections</span>.<span style=\"color:#5f9ea0\">Generic</span>.List&lt;String&gt;();\r\n            <span style=\"color:#a020f0\">using</span> (<span style=\"color:#228b22\">ZipFile</span> <span style=\"color:#b8860b\">zip</span> = <span style=\"color:#5f9ea0\">ZipFile</span>.Read(_zipFileName))\r\n            {\r\n                <span style=\"color:#a020f0\">foreach</span> (<span style=\"color:#228b22\">ZipEntry</span> <span style=\"color:#b8860b\">e</span> <span style=\"color:#a020f0\">in</span> <span style=\"color:#5f9ea0\">zip</span>.Entries)\r\n                {\r\n                    <span style=\"color:#a020f0\">using</span> (<span style=\"color:#228b22\">var</span> <span style=\"color:#b8860b\">ms</span> = <span style=\"color:#a020f0\">new</span> MemoryStream())\r\n                    {\r\n                        <span style=\"color:#5f9ea0\">e</span>.Extract(ms);\r\n\r\n                        <span style=\"color:#228b22\">byte</span>[] <span style=\"color:#b8860b\">block</span> = <span style=\"color:#5f9ea0\">ms</span>.ToArray();\r\n                        <span style=\"color:#228b22\">string</span> <span style=\"color:#b8860b\">contentString</span> = <span style=\"color:#5f9ea0\">System</span>.<span style=\"color:#5f9ea0\">Text</span>.<span style=\"color:#5f9ea0\">Encoding</span>.<span style=\"color:#5f9ea0\">Default</span>.GetString(block, 0, <span style=\"color:#5f9ea0\">block</span>.Length);\r\n                        <span style=\"color:#5f9ea0\">list</span>.Add(contentString);\r\n                    }\r\n                }\r\n            }\r\n</pre>\r\n<p>&nbsp;</p>\r\n<p>But that assumes that all files were encoded with the default text encoding, which may or may not be a valid assumption. If there is a file in the zip, for example, that was UTF-8 encoded, then the string resulting from decoding it with the default encoding will not have the desired content.</p>",
    "PostedDate": "2009-05-08T06:53:52.14-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "188128",
    "ThreadId": "55666",
    "Html": "<p>HI Cheeso, I think you replied just while I was replying as well. I was able to do something very similar to what you suggested and get a single file out of the zipfile into memorystream and then convert that to a string</p>\r\n<p>Where im stuck now is decompressing an unknown number of files in a folder within the zip file back into some form (either memorystream or something else) so that I can manipulate and retrieve them.</p>\r\n<p>Thoughts?</p>\r\n<p>Thanks</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-05-08T06:55:01.72-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "188129",
    "ThreadId": "55666",
    "Html": "<p>Once again our replies crossed over. I will try your second example out.</p>\r\n<p>Thanks</p>",
    "PostedDate": "2009-05-08T06:56:17.113-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]