{"id":84695,"date":"2023-03-17T04:00:20","date_gmt":"2023-03-17T03:00:20","guid":{"rendered":"https:\/\/code-maze.com\/?p=84695"},"modified":"2024-04-16T07:53:25","modified_gmt":"2024-04-16T05:53:25","slug":"csharp-zip-files","status":"publish","type":"post","link":"https:\/\/code-maze.com\/csharp-zip-files\/","title":{"rendered":"Working With Zip Files in C#\/.NET"},"content":{"rendered":"<p>In this article, let&#8217;s look at some of the .NET classes we can use to <strong>read, create, and update zip files<\/strong>.<\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/files-csharp\/ZipFilesInNet\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Today compressed (zip) files are all around us. Unless we have a really (really) old browser, we got this article in compact form to save bandwidth. After our browser asks, the server compresses the article and sends it to our browser. Then the browser uncompresses it and shows it to us.<\/p>\n<h2>Read Zip Files<\/h2>\n<p>We will more likely need to read\/extract files from zip files than create zip files. So, first, let&#8217;s see how to read zip files, list their content, and extract files from them.<\/p>\n<p>In recent years, Microsoft has added support for zip files directly in .NET. <strong>For manipulating a single zip file, we use the <code>ZipFile<\/code> class.\u00a0<\/strong><\/p>\n<h3>ZipFile Class<\/h3>\n<p><code>ZipFile<\/code> is a <a href=\"https:\/\/code-maze.com\/static-classes-csharp\/\" target=\"_blank\" rel=\"noopener\">static class<\/a>, so we can&#8217;t create instances of it, but we can use its public methods. There are only four methods, and they are easy to understand:<\/p>\n\n<table id=\"tablepress-54\" class=\"tablepress tablepress-id-54\">\n<thead>\n<tr class=\"row-1\">\n\t<th class=\"column-1\">Method<\/th><th class=\"column-2\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody class=\"row-striping row-hover\">\n<tr class=\"row-2\">\n\t<td class=\"column-1\"><strong>Open<\/strong><\/td><td class=\"column-2\">Opens a zip file at a specified location using a specified mode and encoding.<\/td>\n<\/tr>\n<tr class=\"row-3\">\n\t<td class=\"column-1\"><strong>OpenRead<\/strong><\/td><td class=\"column-2\">Opens a zip file for reading.<\/td>\n<\/tr>\n<tr class=\"row-4\">\n\t<td class=\"column-1\"><strong>ExtractToDirectory<\/strong><\/td><td class=\"column-2\">Extracts all files in the specified file to a directory on the file system.<\/td>\n<\/tr>\n<tr class=\"row-5\">\n\t<td class=\"column-1\"><strong>CreateFromDirectory<\/strong><\/td><td class=\"column-2\">Creates a zip file that contains the files and directories from the specified directory.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<!-- #tablepress-54 from cache -->\n<p>Each of them can have different parameters. So we can specify the encoding, compression level, and other parameters.\u00a0<\/p>\n<h3>List All Files Contained in the Zip File<\/h3>\n<p><span style=\"font-weight: 400;\">Let\u2019s have a look at how to list the files in a zip file:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using var zipFile = ZipFile.OpenRead(\"multi-folder.zip\");\r\n\r\nvar counter = 0;\r\nforeach (var entry in zipFile.Entries)\r\n    Console.WriteLine($\"{++counter,3}: {entry.Name}\");<\/pre>\n<p>To list all the files in a zip file, we have to open the file and loop through the files. We can open the file with the <code>OpenRead()<\/code> method, as we only read it. After that, we ask the object for the list of all files and display them:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\"> 1: image.png\r\n 2: text-file.txt\r\n 3:\r\n 4: image.png\r\n 5:\r\n 6: image.png\r\n 7:\r\n 8: image.png\r\n 9:\r\n10: image.png<\/pre>\n<p>This is strange output, as one file, named <code>image.png<\/code>, is displayed multiple times. But not only that, there are even empty files. Why? This zip file has a folder structure inside, and these empty spaces are folders. Also, <code>image.png<\/code> files are in different folders.<\/p>\n<p>Let&#8217;s use the <code>FullName<\/code> <a href=\"https:\/\/code-maze.com\/csharp-properties\/\" target=\"_blank\" rel=\"noopener\">property<\/a> instead of the <code>Name<\/code> property <strong>to display the actual structure of the zip file and folder names<\/strong>. So, all we need to change is the <code>WriteLine()<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"5\">using var zipFile = ZipFile.OpenRead(\"multi-folder.zip\");\r\n\r\nvar counter = 0;\r\nforeach (var entry in zipFile.Entries)\r\n    Console.WriteLine($\"{++counter,3}: {entry.FullName}\");<\/pre>\n<p>By running this code, we get the full structure of the zip file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\"> 1: image.png\r\n 2: text-file.txt\r\n 3: folder1\/\r\n 4: folder1\/image.png\r\n 5: folder1\/subfolder11\/\r\n 6: folder1\/subfolder11\/image.png\r\n 7: folder1\/subfolder11\/subfolder111\/\r\n 8: folder1\/subfolder11\/subfolder111\/image.png\r\n 9: folder2\/\r\n10: folder2\/image.png<\/pre>\n<h3>ZipArchiveEntry Class<\/h3>\n<p>The <code>ZipArchiveEntry<\/code> class represents a single file (<strong>an entry<\/strong>) inside the zip file. We have already used two properties, namely <code>Name<\/code>, and <code>FileName<\/code>. This class enables us to examine the properties of an entry, and open or delete the entry. As with the <code>ZipFile<\/code> class, we only discuss the most used properties and methods of the <code>ZipArchiveEntry<\/code> class.<\/p>\n<p>Of all properties, besides <code>Name<\/code> and <code>FullName<\/code>, we should mention <code>Length<\/code> which returns the uncompressed size of the entry.<\/p>\n<p>There are two valuable methods and one very useful <a href=\"https:\/\/code-maze.com\/csharp-static-members-constants-extension-methods\/\" target=\"_blank\" rel=\"noopener\">extension<\/a> method. <strong>The <code>Delete()<\/code> method deletes the entry, the <code>Open()<\/code> method opens the entry and the <code>ExtractToFile()<\/code> extension method extracts an entry to a file.<\/strong><\/p>\n<p>The <code>Open()<\/code> method opens an entry <code>Stream<\/code> and we can operate on that entry as on any other <a href=\"https:\/\/code-maze.com\/csharp-basics-streamwriter-streamreader\/\" target=\"_blank\" rel=\"noopener\">stream<\/a>. But most of the time we rather use the <code>ExtractToFile()<\/code> extension method as it does what we most likely need. <strong>It extracts the entry from the zip file onto the file system<\/strong>, so we don&#8217;t have to work with streams.<\/p>\n<h3>Extract Files From Zip File With ExtractToDirectory() Method<\/h3>\n<p>If we are resourceful, we can extract all files (all entries) by using one function:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">ZipFile.ExtractToDirectory(\"multi-folder.zip\", \"extracted-files\");<\/code><\/p>\n<p>This single line of code extracts all the files in the <code>multi-folder.zip<\/code> file into the subfolder <code>extracted-files<\/code> in our current folder.\u00a0<\/p>\n<p>But there is a catch. If we run our program again, we get an exception:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">System.IO.IOException\r\n  HResult=0x80070050\r\n  Message=The file '...\\image.png' already exists.\r\n  Source=System.Private.CoreLib\r\n  StackTrace: ...<\/pre>\n<p>This method prevents us from accidentally overriding existing files. But if we do want to override files and we are not afraid of losing something important, we can use the third parameter <code>overwriteFiles<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">ZipFile.ExtractToDirectory(\"multi-folder.zip\", \"extracted-files\", true);<\/code><\/p>\n<p><strong>Note, this code overwrites any existing files!<\/strong><\/p>\n<p>Now that the files are on the disk, we can manipulate them as any other.<\/p>\n<h3>Extract Files From Zip File With ExtractToFile() Method<\/h3>\n<p>So we can extract the whole folder with one method, but as we saw, the class <code>ZipArchiveEntry<\/code> also has the <code>ExtractToFile()<\/code> extension method. It extracts concrete entries to a selected folder.<\/p>\n<p>When we use <code>ExtractToFile()<\/code> method, we always have to define a whole path; otherwise, we will save the file in the current folder, which is rarely a good idea. So let us write our version of the<code>ExtractToDirectory()<\/code> method, where we will have to think about the correct folders and sub-folders:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using var zipFile = ZipFile.OpenRead(\"multi-folder.zip\");\r\nvar rootFolder = \"extracted-files\";\r\nforeach (var entry in zipFile.Entries)\r\n{\r\n    var wholePath = Path.Combine(\r\n        rootFolder,\r\n        Path.GetDirectoryName(entry.FullName) ?? string.Empty);\r\n\r\n    if (!Directory.Exists(wholePath))\r\n        Directory.CreateDirectory(wholePath);\r\n\r\n    if (!string.IsNullOrEmpty(entry.Name))\r\n    {\r\n        var wholeFileName = Path.Combine(\r\n            wholePath,\r\n            Path.GetFileName(entry.FullName));\r\n\r\n        entry.ExtractToFile(wholeFileName, true);\r\n    }\r\n}<\/pre>\n<p>First, we have to open the file and set the root folder, and then loop through entries. In the loop, we extract the folder path from the entry. We do that by using the <code>Path.GetDirectoryName()<\/code> method. After extracting the folder, we combine it with the root folder. This is done with the <code>Path.Combine()<\/code> method. If the folder does not exist, we create it with the <code>Directory.CreateDirectory()<\/code> method.<\/p>\n<p>Now we come to a well-known problem. <strong>How do we know if an entry is a file or a<\/strong> <strong>folder? <\/strong>Strangely, Microsoft did not create a method for that. There are a few possibilities, but the easiest is this: <em>if the <code>Name<\/code> is empty, then this is a folder. Otherwise, it is a file.<\/em><\/p>\n<p>So if the <code>Name<\/code> property is not empty, then this entry is a file, and we have to again combine the whole path with the file name to get the correct file on the disk. After we get the file name, we can use the <code>ExtractToFile()<\/code> method and extract the entry to the disk. Again we have to be careful with the second parameter. If set to <code>true<\/code>, we override the file if it already exists.<\/p>\n<p>So, it was quite a journey, but we have learned a lot and written a nice piece of code.\u00a0<\/p>\n<h3>Extract Files With Open() Method<\/h3>\n<p>We can access the <code>Stream<\/code> using the <code>Open()<\/code> method if we don\u2019t need the file on disk but only its content. Let&#8217;s convert each file to its <a href=\"https:\/\/code-maze.com\/base64-encode-decode-csharp\/\" target=\"_blank\" rel=\"noopener\">base64 string<\/a>, so we can send them by email (or something similar):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using var zipFile = ZipFile.OpenRead(\"multi-folder.zip\");\r\nforeach (var entry in zipFile.Entries)\r\n{\r\n    if (!string.IsNullOrEmpty(entry.Name))\r\n    {\r\n        using (var stream = entry.Open())\r\n        using (var memoryStream = new MemoryStream())\r\n        {\r\n            stream.CopyTo(memoryStream);\r\n            var bytes = memoryStream.ToArray();\r\n            var base64 = Convert.ToBase64String(bytes);\r\n            Console.WriteLine($\"{entry.FullName} =&gt; {base64}\");\r\n        }\r\n    }\r\n}<\/pre>\n<p>Here, we are converting all files to their base64 string representation. We loop through the <code>Entries<\/code> and convert only files. We execute the conversion by converting the <code>Stream<\/code> into a <code>Base64<\/code> string.\u00a0<\/p>\n<h2>Create Zip Files<\/h2>\n<p>Creating zip files is just as easy as reading them. Again we can do that on different levels. So we can create a zip file from the whole folder and its subfolders using one single line.<\/p>\n<h3>Compress (Zipping) Whole Folder<\/h3>\n<p><strong>The easiest method to create a zip file is to compress the whole folder:<\/strong><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">ZipFile.CreateFromDirectory(\".\", @\"..\\parent.zip\");<\/code><\/p>\n<p>With this one line of code, we are compressing the whole current folder into a file named <code>parent.zip<\/code>. Also, we can compress any other folder on disk:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">ZipFile.CreateFromDirectory(@\"c:\\temp\", \"my-temp.zip\");<\/code><\/p>\n<p>This compresses the whole temp folder into the file <code>my-temp.zip<\/code>.<\/p>\n<h3>Add Files to a Zip File<\/h3>\n<p>As with extracting entries from the zip file, we can also add entries to zip files:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var folder = new DirectoryInfo(\".\");\r\nFileInfo[] files = folder.GetFiles(\"*.*\", SearchOption.AllDirectories);\r\n\r\nusing var archive = ZipFile.Open(@\"..\\parent.zip\", ZipArchiveMode.Create);\r\n\r\nforeach (var file in files)\r\n{\r\n    archive.CreateEntryFromFile(\r\n        file.FullName,\r\n        Path.GetRelativePath(folder.FullName, file.FullName)\r\n    );\r\n}<\/pre>\n<p>To do the same work as the <code>CreateFromDirectory()<\/code> method, we have to loop through files. First, we use <code>DirectoryInfo<\/code> to get the list of all files in a folder. Next, we create a new zip file and, in a <code>foreach<\/code> loop, add each file to the newly created zip file with the <code>CreateEntryFromFile()<\/code> method.<\/p>\n<p>Again we have 12 lines of code instead of 1. But this is just an example, as with that code we have more freedom. We can compress only selected files and not all files:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-highlight=\"2\">var folder = new DirectoryInfo(\".\");\r\nFileInfo[] files = folder.GetFiles(\"*.txt\", SearchOption.AllDirectories);\r\n\r\nusing var archive = ZipFile.Open(@\"..\\parent.zip\", ZipArchiveMode.Create);\r\n\r\nforeach (var file in files)\r\n{\r\n    archive.CreateEntryFromFile(\r\n        file.FullName,\r\n        Path.GetRelativePath(folder.FullName, file.FullName)\r\n    );\r\n}<\/pre>\n<p>To compress only <code>*.txt<\/code> files, we have to change only one line of code.<\/p>\n<h3>Create a Zip File With Stream<\/h3>\n<p>We have created a zip with a single line of code. Then we also created a zip file by manually adding files. The third option is using <code>Streams<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var helloText = \"Hello world!\";\r\n\r\nusing var archive = ZipFile.Open(@\"..\\test.zip\", ZipArchiveMode.Create);\r\n\r\nvar entry = archive.CreateEntry(\"hello.txt\");\r\n\r\nusing (Stream st = entry.Open())\r\nusing (StreamWriter writerManifest = new StreamWriter(st))\r\nwriterManifest.WriteLine(helloText);<\/pre>\n<p>Here, we create a new zip file named <code>test.zip<\/code> containing a single file named <code>hello.txt<\/code> with the text <em>&#8220;Hello world&#8221;<\/em>.<\/p>\n<h3>Compression Level<\/h3>\n<p>Sometimes when creating zip files, <strong>it is also important how much we want to compress them<\/strong>. For that reason methods also accept a compression-level parameter. If we do not specify the compression level, then .NET uses the default.<\/p>\n<p>We have four options, ranging from no compression at all to the best compression: <code>NoCompression<\/code>, <code>Fastest<\/code>, <code>Optimal<\/code>, and <code>SmallestSize<\/code>. With compression, there is a trade-off with speed. <strong>So the more compression we want, the slower the program will get<\/strong>, but the result will be a smaller file.\u00a0<\/p>\n<p>In our previous example, we could demand the best possible compression by setting the parameter to <code>CompressionLevel.SmallestSize<\/code>:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">var entry = archive.CreateEntry(\"hello.txt\", CompressionLevel.SmallestSize);<\/code><\/p>\n<p>This code uses the best but slowest possible compression.<\/p>\n<p><em>Note: with our small zip file containing one TXT file with the text &#8216;Hello world&#8217; compression is not an issue. But with larger zip files, there can be a significant difference in size.<\/em><\/p>\n<h2>Delete Entries From Zip Files<\/h2>\n<p>We know how to read and write zip files, so there is only one rarely-used method left, <code>Delete()<\/code>. We can in fact, also delete entries from zip files.<\/p>\n<p>So let&#8217;s delete all files with the name &#8220;image.png&#8221; from a zip file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">using var zipFile = ZipFile.Open(\"multi-folder.zip\", ZipArchiveMode.Update);\r\n\r\nvar images = zipFile.Entries.Where(e =&gt; e.Name == \"image.png\").ToList();\r\n\r\nfor (int i = images.Count - 1; i &gt;= 0; --i)\r\n    images[i].Delete();<\/pre>\n<p>First, we open the zip file for modifications. Then we select all files named &#8220;image.png&#8221; from the <code>Entries<\/code> property. After that, we delete them by using the <code>Delete()<\/code> method.<\/p>\n<h2>Conclusion<\/h2>\n<p>Working with zip files in .NET is a joy. Objects are easy to use, and the code is clean.<\/p>\n<p>When working with zip files, we mostly want to compress the whole folder on a disk or uncompress the whole zip file onto a disk. Fortunately, we can achieve both operations with a single line of code.<\/p>\n<p>We looked at how to add files (an entry) to a zip file, as well as extract them. If we want to dig even deeper, we can always use Streams.<\/p>\n<p>But, as always, there is one piece missing. If we want to use password-protected zip files, we should use some external libraries.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, let&#8217;s look at some of the .NET classes we can use to read, create, and update zip files. Today compressed (zip) files are all around us. Unless we have a really (really) old browser, we got this article in compact form to save bandwidth. After our browser asks, the server compresses the [&hellip;]<\/p>\n","protected":false},"author":53,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[10,1696,476,1695,1693,1694],"class_list":["post-84695","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-net","tag-create-zip-files","tag-dotnet","tag-extract-files-from-zip-file","tag-zip-files","tag-ziparchiveentry-class","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Working With Zip Files in C#\/.NET - Code Maze<\/title>\n<meta name=\"description\" content=\"In this article, we explore the various ways of working with Zip Files in C#, learning how to read, create and delete files from them.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/csharp-zip-files\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working With Zip Files in C#\/.NET - Code Maze\" \/>\n<meta property=\"og:description\" content=\"In this article, we explore the various ways of working with Zip Files in C#, learning how to read, create and delete files from them.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/csharp-zip-files\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-17T03:00:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-16T05:53:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Matjaz Prtenjak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matjaz Prtenjak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/\"},\"author\":{\"name\":\"Matjaz Prtenjak\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589\"},\"headline\":\"Working With Zip Files in C#\/.NET\",\"datePublished\":\"2023-03-17T03:00:20+00:00\",\"dateModified\":\"2024-04-16T05:53:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/\"},\"wordCount\":1585,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\".NET\",\"Create ZIP files\",\"dotnet\",\"Extract Files From Zip File\",\"zip files\",\"ZipArchiveEntry Class\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/csharp-zip-files\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/\",\"url\":\"https:\/\/code-maze.com\/csharp-zip-files\/\",\"name\":\"Working With Zip Files in C#\/.NET - Code Maze\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2023-03-17T03:00:20+00:00\",\"dateModified\":\"2024-04-16T05:53:25+00:00\",\"description\":\"In this article, we explore the various ways of working with Zip Files in C#, learning how to read, create and delete files from them.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/csharp-zip-files\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/csharp-zip-files\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Working With Zip Files in C#\/.NET\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589\",\"name\":\"Matjaz Prtenjak\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg\",\"caption\":\"Matjaz Prtenjak\"},\"description\":\"Matjaz is a seasoned professional with over 25 years of expertise in software development. He began his programming journey during the era when IBM dominated with mainframe computers, and personal computers were yet to be born. He possesses a rich background and has authored two books on C++ and VBA programming languages. Lately, he has dedicated himself to harnessing the power of .NET technology in his innovative projects.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/mprtenja\/\"],\"url\":\"https:\/\/code-maze.com\/author\/mprtenjak\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Working With Zip Files in C#\/.NET - Code Maze","description":"In this article, we explore the various ways of working with Zip Files in C#, learning how to read, create and delete files from them.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/csharp-zip-files\/","og_locale":"en_US","og_type":"article","og_title":"Working With Zip Files in C#\/.NET - Code Maze","og_description":"In this article, we explore the various ways of working with Zip Files in C#, learning how to read, create and delete files from them.","og_url":"https:\/\/code-maze.com\/csharp-zip-files\/","og_site_name":"Code Maze","article_published_time":"2023-03-17T03:00:20+00:00","article_modified_time":"2024-04-16T05:53:25+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Matjaz Prtenjak","twitter_card":"summary_large_image","twitter_creator":"@CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Matjaz Prtenjak","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/csharp-zip-files\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/csharp-zip-files\/"},"author":{"name":"Matjaz Prtenjak","@id":"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589"},"headline":"Working With Zip Files in C#\/.NET","datePublished":"2023-03-17T03:00:20+00:00","dateModified":"2024-04-16T05:53:25+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/csharp-zip-files\/"},"wordCount":1585,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":[".NET","Create ZIP files","dotnet","Extract Files From Zip File","zip files","ZipArchiveEntry Class"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/csharp-zip-files\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/csharp-zip-files\/","url":"https:\/\/code-maze.com\/csharp-zip-files\/","name":"Working With Zip Files in C#\/.NET - Code Maze","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2023-03-17T03:00:20+00:00","dateModified":"2024-04-16T05:53:25+00:00","description":"In this article, we explore the various ways of working with Zip Files in C#, learning how to read, create and delete files from them.","breadcrumb":{"@id":"https:\/\/code-maze.com\/csharp-zip-files\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/csharp-zip-files\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/csharp-zip-files\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/csharp-zip-files\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Working With Zip Files in C#\/.NET"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589","name":"Matjaz Prtenjak","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg","caption":"Matjaz Prtenjak"},"description":"Matjaz is a seasoned professional with over 25 years of expertise in software development. He began his programming journey during the era when IBM dominated with mainframe computers, and personal computers were yet to be born. He possesses a rich background and has authored two books on C++ and VBA programming languages. Lately, he has dedicated himself to harnessing the power of .NET technology in his innovative projects.","sameAs":["https:\/\/www.linkedin.com\/in\/mprtenja\/"],"url":"https:\/\/code-maze.com\/author\/mprtenjak\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/84695","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=84695"}],"version-history":[{"count":8,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/84695\/revisions"}],"predecessor-version":[{"id":116504,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/84695\/revisions\/116504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=84695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=84695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=84695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}