{"id":2094,"date":"2017-01-18T15:07:46","date_gmt":"2017-01-18T14:07:46","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=2094"},"modified":"2017-01-18T15:19:28","modified_gmt":"2017-01-18T14:19:28","slug":"c-net-zip-dateien-entpacken-und-im-zielverzeichnis-ggf-ueberschreiben-uncomrpess-zip-to-a-folder-and-overwrite-existing","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=2094","title":{"rendered":"C#.NET: ZIP Dateien entpacken und im Zielverzeichnis ggf. \u00fcberschreiben \/ Uncomrpess ZIP to a folder and overwrite existing"},"content":{"rendered":"<h1>Problem<\/h1>\n<p>Die ZipFile.ExtractToDirectory(zip,target)-Methode in C# \u00fcberschreibt keine vorhandenen Dateien, sondern schmeisst eine Exception.<br \/>\nThe ZipFile.ExtractToDirectory(zip,target)-method in c# is not overwriting existing files, but throws an exception<\/p>\n<h1>Vorraussetzung &#8211; Prerequirements<\/h1>\n<p>.NET Framework der Version 4.5<br \/>\nReferenzen\/References:<br \/>\nSystem.IO.Compression.dll<br \/>\nSystem.IO.Compression.FileSystem.dll<\/p>\n<p>You have to import the using<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing System.IO.Compression;\r\n<\/pre>\n<h1>Ansatz &#8211; Approach<\/h1>\n<p>Durch die Iteration \u00fcber das ZIP-Archiv lassen sich die einzelnen Dateien entpacken, wobei die Methode System.IO.Compression.ZipArchiveEntry.ExtractToFile(string path, bool overwrite) ein \u00dcberschreiben erlaubt.<\/p>\n<p>The iteration on System.IO.Compression.ZipArchive with System.IO.Compression.ZipArchiveEntry.ExtractToFile(string path, bool overwrite) allows to overwrite existing files.<\/p>\n<h1>L\u00f6sung &#8211; Solution<\/h1>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\npublic void ZipFileExtractToDirectory(string zipPath, string extractPath)\r\n{\r\n  using(System.IO.Compression.ZipArchive archive = ZipFile.OpenRead(zipPath))\r\n  {\r\n    foreach(ZipArchiveEntry entry in archive.Entries)\r\n    {\r\n      string completeFileName = Path.Combine(extractPath, entry.FullName);\r\n      string directory = Path.GetDirectoryName(completeFileName);\r\n\r\n      if (!Directory.Exists(directory))\r\n      {\r\n        Directory.CreateDirectory(directory);\r\n      }\r\n      entry.ExtractToFile(completeFileName, true);\r\n    }\r\n  }\r\n}\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D2094&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Problem Die ZipFile.ExtractToDirectory(zip,target)-Methode in C# \u00fcberschreibt keine vorhandenen Dateien, sondern schmeisst eine Exception. The ZipFile.ExtractToDirectory(zip,target)-method in c# is not overwriting existing files, but throws an exception Vorraussetzung &#8211; Prerequirements .NET Framework der Version 4.5 Referenzen\/References: System.IO.Compression.dll System.IO.Compression.FileSystem.dll You have to import the using using System.IO.Compression; Ansatz &#8211; Approach Durch die Iteration \u00fcber das ZIP-Archiv lassen &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=2094\" class=\"more-link\"><span class=\"screen-reader-text\">C#.NET: ZIP Dateien entpacken und im Zielverzeichnis ggf. \u00fcberschreiben \/ Uncomrpess ZIP to a folder and overwrite existing<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[33,3],"tags":[],"class_list":["post-2094","post","type-post","status-publish","format-standard","hentry","category-c","category-programmierung"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-xM","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2094","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2094"}],"version-history":[{"count":4,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2094\/revisions"}],"predecessor-version":[{"id":2098,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2094\/revisions\/2098"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2094"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2094"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2094"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}