[
  {
    "Id": "230501",
    "ThreadId": "67821",
    "Html": "<p>Hello, good morning or good evening :-)</p>\r\n<p>I am beginner with use the DotNetZip-Library and I am not a professional programmer with Visual Basic, sorry for that and the following question when it is easy to solve (but not for me).</p>\r\n<p>To open a ZIP-File I use the DotNetZip-Library and I can unzip oder zip needed files and more, it is very easy to work.</p>\r\n<p>Now I have a problem, I must open/read a ZIP-File, but within this file I have a further ZIP-File. Within this ZIP-File I must find two XML-Files, the first one is a manifest.xml, the second file is an other XML-File. To open the second xml file, I must read the manifest.xml, search for a TAG within this file to read the name of the second xml file.</p>\r\n<p>In my first question (one or two week ago) I have wrote that it is not allowed for me to extract this file, and so I must use a memory-stream for my operation with this files.</p>\r\n<p>Has anyone a idea how can I read the ZIP-File with a memory-stream, then read the ZIP-File within this memory-stream to open the manifest.xml?</p>\r\n<p>The next problem is, when I have opend the second xml file within the second ZIP-File and change a entry, how can I save back the changes without save the ZIP- or XML-ile on my harddisk?</p>\r\n<p>I an single ZIP-File I can read a XML-File with XDocument.parse(...), this is not the problem. But how can I read an XML-File within a Zip- in Zip-File and save back to the Zip- in Zip-File?</p>\r\n<p>This is a big problem for me on this time and I am very happy when anyone can help me with an idea to do this.</p>\r\n<p>Sorry, I use a translator and I hope that is not to confused for you :-)</p>\r\n<p>Regards,<br>Maximilian</p>",
    "PostedDate": "2009-09-02T22:00:19.657-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "230583",
    "ThreadId": "67821",
    "Html": "<div style=\"color:Black;background-color:White\">\r\n<pre><span style=\"color:Blue\">Public</span> <span style=\"color:Blue\">Sub</span> ModifyToplevelZip\r\n    <span style=\"color:Blue\">Using</span> zip1 <span style=\"color:Blue\">as</span> ZipFile = ZipFile.Read(<span style=\"color:#A31515\">&quot;Embedded.zip&quot;</span>)\r\n        <span style=\"color:Blue\">Using</span> ms1 <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> MemoryStream\r\n            <span style=\"color:Green\">'' ms1 will hold the original inner zip</span>\r\n            zip1(<span style=\"color:#A31515\">&quot;Payload.zip&quot;</span>).Extract(ms1)\r\n            ms1.Seek(0, SeekOrigin.Begin)\r\n            <span style=\"color:Blue\">Using</span> ms2 <span style=\"color:Blue\">As</span> MemoryStream = GetModifiedZip(ms1)\r\n                zip1.UpdateEntry(<span style=\"color:#A31515\">&quot;Payload.zip&quot;</span>, <span style=\"color:#A31515\">&quot;&quot;</span>, ms2)\r\n                <span style=\"color:Green\">'' save to the toplevel zip, in the filesystem</span>\r\n                zip1.Save\r\n            <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n        <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>        \r\n<span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Sub</span>\r\n\r\n<span style=\"color:Blue\">Public</span> <span style=\"color:Blue\">Function</span> GetModifiedZip (<span style=\"color:Blue\">ByVal</span> ms <span style=\"color:Blue\">As</span> MemoryStream) <span style=\"color:Blue\">As</span> MemoryStream\r\n    <span style=\"color:Blue\">Dim</span> msOut <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> MemoryStream\r\n    <span style=\"color:Blue\">Using</span> zip2 <span style=\"color:Blue\">as</span> ZipFile = ZipFile.Read(ms)\r\n        <span style=\"color:Blue\">Using</span> manifest <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">New</span> MemoryStream\r\n            zip2(<span style=\"color:#A31515\">&quot;manifest.xml&quot;</span>).Extract(manifest)\r\n\r\n            Console.WriteLine(<span style=\"color:#A31515\">&quot;manifest: {0}&quot;</span>, System.Text.Encoding.ASCII.GetString(manifest.ToArray()))\r\n            manifest.Seek(0,SeekOrigin.Begin)\r\n            <span style=\"color:Green\">' at this point, manifest contains the contents of the manifest.xml</span>\r\n\r\n            <span style=\"color:Blue\">Dim</span> entryName <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span> = <span style=\"color:Blue\">Nothing</span>\r\n            <span style=\"color:Blue\">Using</span> reader <span style=\"color:Blue\">As</span> XmlReader = XmlReader.Create(manifest)\r\n                <span style=\"color:Green\">' Move the reader to the root element.</span>\r\n                reader.MoveToContent()\r\n                entryName = reader.ReadElementString()\r\n                <span style=\"color:Green\">' Read the title and price elements.</span>\r\n                Console.WriteLine(<span style=\"color:#A31515\">&quot;entry name: {0}&quot;</span>, entryName)\r\n            <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n\r\n            <span style=\"color:Green\">' entryName now contains the name of the entry that must be modified</span>\r\n\r\n            <span style=\"color:Blue\">Dim</span> entry <span style=\"color:Blue\">As</span> ZipEntry = zip2(entryName)\r\n            <span style=\"color:Blue\">Dim</span> intValue <span style=\"color:Blue\">As</span> Int32\r\n            <span style=\"color:Blue\">Using</span> reader <span style=\"color:Blue\">As</span> XmlReader = XmlReader.Create(entry.OpenReader)\r\n                reader.MoveToContent()\r\n                <span style=\"color:Blue\">Dim</span> nodeValue <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span> = reader.ReadElementString()\r\n                Console.WriteLine(<span style=\"color:#A31515\">&quot;nodeValue: {0}&quot;</span>, nodeValue)\r\n                intValue = Int32.Parse(nodeValue)\r\n            <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n\r\n            intValue = intValue + 1\r\n            <span style=\"color:Blue\">Dim</span> newXmlContent <span style=\"color:Blue\">As</span> <span style=\"color:Blue\">String</span> = <span style=\"color:Blue\">String</span>.Format(<span style=\"color:#A31515\">&quot;&lt;count&gt;{0}&lt;/count&gt;&quot;</span>, intValue)\r\n            zip2.UpdateEntry(entryName, <span style=\"color:#A31515\">&quot;&quot;</span>, newXmlContent)\r\n            zip2.Save(msOut)\r\n        <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n    <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n    msOut.Seek(0, SeekOrigin.Begin)\r\n    <span style=\"color:Blue\">Return</span> msOut\r\n<span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Function</span>\r\n\r\n\r\n</pre>\r\n</div>",
    "PostedDate": "2009-09-03T02:05:48.43-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "230595",
    "ThreadId": "67821",
    "Html": "<p>Hello Cheeso,</p>\r\n<p>you are great, I test your code and come back later with the result.</p>\r\n<p>I had seen that I can read a entry within the ZIP-File with a &quot;CrcCalculatorStream&quot;, I can test it if the entry readable or not?<br>In my testings I had one ZIP-File who was bad and so I need a check-routine to test the ZIP-File it is readable, empty or bad. This is my next step when I can use your code.</p>\r\n<p>Thanks a lot of this time :-)</p>\r\n<p>Regards,<br>Maximilian</p>",
    "PostedDate": "2009-09-03T02:51:04.03-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "230741",
    "ThreadId": "67821",
    "Html": "<p>There is a static (Shared) CheckZip method on the ZipFile class.&nbsp; There's also a method called IsZipFile.&nbsp; Either of those can read from a stream.</p>\r\n<p>You can use one of those to check&nbsp;the zip in the way you want.&nbsp;</p>",
    "PostedDate": "2009-09-03T09:26:30.7-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "230834",
    "ThreadId": "67821",
    "Html": "<p>one more thing - to use that code I posted, if you use v1.9,&nbsp;&nbsp;you need at least v1.9.0.2 - the latest version on the site right now.&nbsp;&nbsp; There was a bug in v1.9.0.1 that would prevent it from working.</p>\r\n<p>if you are using v1.8, then you can use 1.8.4.22.&nbsp;</p>",
    "PostedDate": "2009-09-03T12:40:30.99-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231103",
    "ThreadId": "67821",
    "Html": "<p>Hello Cheeso,</p>\r\n<p>can I check a ZIP-File for an existing entry like &quot;If Zip.ZipFile(filename).IsExist(entryname) then ... End If&quot; ?</p>\r\n<p>I have used your code, but I had a problem to read a specific TAG. The manifest.xml looks like that and I need the value from &lt;machine&gt;&lt;location&gt;:<br>&lt;config id=&quot;&quot; instance=&quot;&quot;&gt;<br>&nbsp; &lt;machine&gt;<br>&nbsp;&nbsp;&nbsp; &lt;location&gt;business&lt;/location<br>&nbsp; &lt;/machine&gt;<br>&nbsp; &lt;system&gt;<br>&nbsp;&nbsp;&nbsp; &lt;location&gt;bla&lt;/location&gt;<br>&nbsp; &lt;/system&gt;<br>&lt;/config&gt;</p>\r\n<p>I have tested with XmlReader, but I can't find a way to read exactly the needed value and it is possible that we have more that one entry named &lt;location&gt; in other TAGs under the root &lt;config...&gt;</p>\r\n<p>To use a select-command (Linq) I must work with XDocument, but with XDocument.load I cannot read a memorystream, I'm very confused and cannot find the correct way.</p>\r\n<p>For this time I read the lines step by step and search for the word &lt;location&gt;, but this is a very bad way.</p>\r\n<p>I would like to locate a entry within the same zipfile as the manifest.xml, for this I need the function from my first question (IfExist...).</p>\r\n<p>Kind regards,<br>Maximilian</p>",
    "PostedDate": "2009-09-04T04:58:21.293-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231138",
    "ThreadId": "67821",
    "Html": "<p>you can pass an XmlRader to XDocument.Load(), and you can create an XmlReader using a MemoryStream.</p>",
    "PostedDate": "2009-09-04T07:11:54.97-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231158",
    "ThreadId": "67821",
    "Html": "<p>Hello Cheeso,</p>\r\n<p>thanks, I use now a XmlReader and it works.</p>\r\n<p>But how can I check for an existing file within the zipfile, here the &quot;\\manifest.xml&quot;?</p>\r\n<p>I would like to test it before I read the specific file and get an error when the file is not existing.</p>\r\n<p>Best regards,</p>\r\n<p>Maximilian</p>\r\n<p>PS:</p>\r\n<p>For donating your project can I make this without paypal? I don't have a paypal-account.</p>",
    "PostedDate": "2009-09-04T08:00:28.647-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231159",
    "ThreadId": "67821",
    "Html": "<p>To test for existence of an entry, use the string indexer, zip(&quot;Manifest.xml&quot;) will be Nothing if the named entry does&nbsp; not exist in the zip file.</p>\r\n<p>For donations, Paypal takes credit cards.&nbsp; you don't need a paypal&nbsp;account.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-09-04T08:08:14.137-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231171",
    "ThreadId": "67821",
    "Html": "<p>and how can I check whether the file exists in the root?</p>\r\n<p>if ZipFile(&quot;manifest.xml&quot;) is nothing then .... end if ==&gt; works<br>if ZipFile(&quot;/manifest.xml&quot;) is nothing then .... end if ==&gt; works not</p>\r\n<p>It is possible that the manifest.xml exists in the root and als&nbsp;under a folder.</p>",
    "PostedDate": "2009-09-04T08:36:10.72-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "231187",
    "ThreadId": "67821",
    "Html": "<p>ZipFile(&quot;manifest.xml&quot;) is in the root</p>\r\n<p>ZipFile(&quot;/manifest.xml&quot;) is also in the root.</p>\r\n<p>Some zip libraries or tools prepend a leading slash, and some do not.&nbsp;&nbsp; DotNetZip treats &quot;/manifest.xml&quot; and &quot;manifest.xml&quot; as the same.</p>\r\n<p>ZipFile(&quot;/some/other/directory/manifest.xml&quot;) is in a different directory.</p>\r\n<p>You can also use backslashes.&nbsp; They are equivalent, for the purposes of the string indexer, to forward slashes.</p>",
    "PostedDate": "2009-09-04T09:11:11.863-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]