[
  {
    "Id": "507737",
    "ThreadId": "231033",
    "Html": "<p>Hello,</p>\r\n<p>I have been trying to work out how to extract a file to a variable rather than creating a file on the hard drive.</p>\r\n<p>Specifically, I am trying to read the document.xml file from within a .docx file and I&nbsp;only want to process the file and not store it.</p>\r\n<p>I am using C#. Is there a method for this? I have seen some sample code on a website that uses ionic.utils.zip.ZipFile.Extract(filepath, stream). Is this no longer available?</p>",
    "PostedDate": "2010-10-15T05:55:28.107-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "507741",
    "ThreadId": "231033",
    "Html": "<p>There are two ways to do what you want.</p>\r\n<p><a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/ea82f312-372e-edad-d374-8db2486e70ba.htm\">ZipEntry.OpenReader()</a> and <a href=\"http://cheeso.members.winisp.net/DotNetZipHelp/html/8e64cfe0-5dfc-2682-2c10-cb840ed3bfa1.htm\">ZipEntry.Extract(Stream)</a>.&nbsp; Using the former, you can just read into your own buffer.&nbsp; If you use the latter, you can extract to a MemoryStream, then examine the buffer associated to the MemoryStream.</p>\r\n<p>ps: yes, the ZipFile.Extract() methods have been removed as an unnecessary duplication.&nbsp; The Extract() methods are now present on the ZipEntry class.&nbsp; If you point me to the specific sample code on the DotNetZip website that uses ZipFile.Extract(), I'll fix it.&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2010-10-15T06:10:40.077-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "507752",
    "ThreadId": "231033",
    "Html": "<p>Thanks Cheeso thats exactly what I need.</p>\r\n<p>I'm not a great programmer though and still having some problems working out how to get my ZipEntry from the ZipFile. I have opened the zip file with ZipFile.Read(string), but am not sure how to search the collection of entries in the ZipFile object&nbsp;for the document.xml file. Please help.</p>",
    "PostedDate": "2010-10-15T06:30:40.617-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "507763",
    "ThreadId": "231033",
    "Html": "<p>think i've got it but havent tested it:</p>\r\n<p><span style=\"color:#0000ff;font-size:x-small\"><span style=\"color:#0000ff;font-size:x-small\"><span style=\"color:#0000ff;font-size:x-small\"><span style=\"color:#0000ff;font-size:x-small\"><span style=\"color:#0000ff;font-size:x-small\"><font size=2 color=\"#0000ff\">\r\n<p>using</p>\r\n</font></span></span><span style=\"font-size:x-small\">(</span><span style=\"color:#2b91af;font-size:x-small\"><span style=\"color:#2b91af;font-size:x-small\">ZipFile</span></span><span style=\"font-size:x-small\"> zip = </span><span style=\"color:#2b91af;font-size:x-small\"><span style=\"color:#2b91af;font-size:x-small\">ZipFile</span></span><span style=\"font-size:x-small\">.Read(filename)) </span></span></span></span><span style=\"font-size:x-small\"></span>\r\n<p><span style=\"font-size:x-small\"><span style=\"font-size:x-small\">\r\n<p>&nbsp;<span style=\"color:#2b91af;font-size:x-small\"><span style=\"color:#2b91af;font-size:x-small\">ZipEntry</span></span><span style=\"font-size:x-small\"> entry = zip.Single();</span><span style=\"font-size:x-small\"><span style=\"font-size:x-small\"> </span></span></p>\r\n</span></span><span style=\"font-size:x-small\"><span style=\"font-size:x-small\">\r\n<p>&nbsp;<span style=\"color:#2b91af;font-size:x-small\"><span style=\"color:#2b91af;font-size:x-small\">MemoryStream</span></span><span style=\"font-size:x-small\"> stream = </span><span style=\"color:#0000ff;font-size:x-small\"><span style=\"color:#0000ff;font-size:x-small\">new</span></span><span style=\"font-size:x-small\"> </span><span style=\"color:#2b91af;font-size:x-small\"><span style=\"color:#2b91af;font-size:x-small\">MemoryStream</span></span><span style=\"font-size:x-small\">();</span></p>\r\n</span></span>\r\n<p><span style=\"font-size:x-small\">\r\n<p>entry.Extract(stream);</p>\r\n<p>}</p>\r\n</span></p>\r\n</p>\r\n</p>\r\n<p>\r\n<p>{</p>\r\n<span style=\"font-size:x-small\">\r\n<p>&nbsp;<span style=\"color:#2b91af;font-size:x-small\"><span style=\"color:#2b91af;font-size:x-small\">ICollection</span></span><span style=\"font-size:x-small\">&lt;</span><span style=\"color:#2b91af;font-size:x-small\"><span style=\"color:#2b91af;font-size:x-small\">ZipEntry</span></span><span style=\"font-size:x-small\">&gt; entries = zip.SelectEntries(</span><span style=\"color:#a31515;font-size:x-small\"><span style=\"color:#a31515;font-size:x-small\">&quot;name = document.xml&quot;</span></span><span style=\"font-size:x-small\">);</span></p>\r\n</span></p>",
    "PostedDate": "2010-10-15T06:46:35.06-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "507766",
    "ThreadId": "231033",
    "Html": "<p>That did not come out how i pasted it:</p>\r\n<p><span style=\"color:blue;font-size:10pt\">using</span><span style=\"font-size:10pt\"> (<span style=\"color:#2b91af\">ZipFile</span> zip = <span style=\"color:#2b91af\">ZipFile</span>.Read(filename))</span></p>\r\n<p><span style=\"font-size:10pt\">{</span></p>\r\n<p><span style=\"font-size:10pt\">&nbsp;&nbsp; <span style=\"color:#2b91af\">ICollection</span>&lt;<span style=\"color:#2b91af\">ZipEntry</span>&gt; entries = zip.SelectEntries(<span style=\"color:#a31515\">&quot;name = document.xml&quot;</span>);</span></p>\r\n<p><span style=\"font-size:10pt\">&nbsp;&nbsp; <span style=\"color:#2b91af\">ZipEntry</span> entry = zip.Single();</span></p>\r\n<p><span style=\"font-size:10pt\">&nbsp;&nbsp; <span style=\"color:#2b91af\">MemoryStream</span> stream = <span style=\"color:blue\">new</span> <span style=\"color:#2b91af\">MemoryStream</span>();</span></p>\r\n<p><span style=\"font-size:10pt\">&nbsp;&nbsp; entry.Extract(stream);</span></p>\r\n<p><span style=\"font-size:10pt\">}</span></p>",
    "PostedDate": "2010-10-15T06:48:13.493-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "509000",
    "ThreadId": "231033",
    "Html": "<p>ok, that looks reasonable.&nbsp; (If you are selecting on zipentry name only, rather than use the ZipFile.SelectEntries() method, &nbsp;you can alternatively use the string indexer on ZipFile.&nbsp;&nbsp;zip[&quot;document.xml&quot;]. )</p>\r\n<p>Once&nbsp; you've extracted the entry to the MemoryStream, you can examine the contents or do whatever else you like with the data.</p>",
    "PostedDate": "2010-10-18T14:28:07.513-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]