[
  {
    "Id": "217703",
    "ThreadId": "64033",
    "Html": "<p>I must be having a dumb day.&nbsp; I want to do something simple: extract a specific file from a zip archive to a different root folder.&nbsp; In the code fragment below, I get a warning that <strong>zip.extract</strong> is obsolete and to use <strong>zipentry.extract</strong>.&nbsp; If I use zipentry, Intellisense shows only two methods: Equals and ReferenceEquals, no extract method.&nbsp; If I create my own instance of zipentry, I now get an Intellisense displayed method of extract BUT now I get a warning not to use <strong>zipentry.extract</strong> but to use <strong>zip.extract</strong>.&nbsp; I think we're stuck in an infinite loop here.&nbsp; So let me ask:&nbsp; How do I extract a specific member of a zip to a new location where I specify the root drive and folder and an overwrite=True option?</p>\r\n<p>Thanks much!</p>\r\n<p>Using zip As ZipFile = ZipFile.Read(sZipPath)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each sFileName As String In zip.EntryFileNames<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If sFileName = sFilePath Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; zip.Extract(sFileName, sRootFolder, True)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim ZE As New ZipEntry<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ZE.Extract(sRootFolder, True)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Using</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-30T11:24:37.307-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "217705",
    "ThreadId": "64033",
    "Html": "<p>You're not actually in an infinite loop.&nbsp; The first warning says to use the Extract() method on the ZipEntry instance.&nbsp; The second warning suggests that you use the overload of ZipEntry.Extract that accepts a ExtractExistingFileAction, rather than a True/False.</p>\r\n<p>To get a zip entry given an entry name, you can use the string indexer.&nbsp; So, the resulting code is:</p>\r\n<pre>  Using zip As ZipFile = ZipFile.Read(sZipPath)\r\n     For Each sFileName As String In zip.EntryFileNames\r\n        If sFileName = sFilePath Then\r\n           zip(sFileName).Extract(sRootFolder, ExtractExistingFileAction.OverwriteSilently)\r\n        End If\r\n     Next\r\n  End Using\r\n</pre>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-30T11:42:20.39-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "217710",
    "ThreadId": "64033",
    "Html": "<p>Fast response!&nbsp;&nbsp; I'll give it a try!&nbsp; Thanks!</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-30T11:51:53.53-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "217746",
    "ThreadId": "64033",
    "Html": "<p>It worked like a charm!&nbsp;</p>\r\n<p>May I suggest it might be the inspiration for an example in the help file?</p>\r\n<p>Thanks Cheeso!</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-30T13:25:25.453-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "217747",
    "ThreadId": "64033",
    "Html": "<p>that's a good suggestion.</p>",
    "PostedDate": "2009-07-30T13:33:23.567-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "217759",
    "ThreadId": "64033",
    "Html": "<p>after further review, I think for your purposes the code could be simpler:</p>\r\n<pre>  Using zip As ZipFile = ZipFile.Read(sZipPath)\r\n      If zip.EntryFileNames.Contains(sFilePath)\r\n          Console.WriteLine(&quot;Extracting {0} to dir {1}&quot;, sFilePath, sRootFolder)\r\n          zip(sFilePath).Extract(sRootFolder, ExtractExistingFileAction.OverwriteSilently)\r\n      End If\r\n  End Using\r\n</pre>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-30T13:54:38.69-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "217789",
    "ThreadId": "64033",
    "Html": "<p>I like the more concise version!&nbsp; I'll use it!</p>\r\n<p>However, I did run into an issue trying to match my filename against the zip entries:&nbsp; my path uses backslashes but in the zip they are stored with forward slashes.&nbsp;&nbsp;&nbsp; I'm now replacing \\ with / before comparing.&nbsp; Did I miss something in the chm file?&nbsp; Is that a reasonable way to do it?</p>\r\n<p>Continuing thanks for your great support!</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-30T15:14:12.277-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "217814",
    "ThreadId": "64033",
    "Html": "<p>yes, that's a reasonable way to do it.&nbsp; OR,&nbsp; you can use the string indexer and test for Nothing.&nbsp; Like this:</p>\r\n<pre>  Using zip As ZipFile = ZipFile.Read(sZipPath)\r\n      Dim ze as ZipEntry = zip(sFilePath)\r\n      If Not ze Is Nothing\r\n          Console.WriteLine(&quot;Extracting {0} to dir {1}&quot;, sFilePath, sRootFolder)\r\n          ze.Extract(sRootFolder, ExtractExistingFileAction.OverwriteSilently)\r\n      End If\r\n  End Using\r\n</pre>\r\n<p>Inside the string indexer on the ZipFile, it does the slash-swapping implicitly. If the named entry is not found in the ZipFile, then the string indexer returns a Nothing value. Keep in mind that paths inside the zipfile never include drive letters. So you may still have to strip that from sFilePath, if it is present.</p>",
    "PostedDate": "2009-07-30T17:13:41.87-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "218160",
    "ThreadId": "64033",
    "Html": "<p>OK, I'll just do the replace.&nbsp;</p>\r\n<p>Your extract function works so quickly that I've changed the app design to permit real-time viewing of archived files.&nbsp;</p>\r\n<p>Thanks Cheeso, great work!</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-07-31T13:55:40.347-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]