-1

Hello today I started to work on a project in c# that need to get all files from zip file but the pint was that I need to make it on my own . I can't use other lit or something any idea how to start or even to build something that will work .....

Thanks. Sorry that I don't provide a code but I don't have any .

dotbot
  • 1
  • 2

3 Answers3

2

.NET Framework has ZipFile class for that.

https://msdn.microsoft.com/en-us/library/system.io.compression.zipfile.openread%28v=vs.110%29.aspx

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string zipPath = @"c:\example\start.zip";
            string extractPath = @"c:\example\extract";

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                    {
                        entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
                    }
                }
            } 
        }
    }
}
Eldarien
  • 813
  • 6
  • 10
  • I already try with this one but the person thatthat give me the work don't won't to use the Microsoft one – dotbot Sep 07 '15 at 19:12
  • Any other idea how to get some code for this on work . – dotbot Sep 07 '15 at 19:15
  • If this is a lab work or something similar then take a look at format specification - https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT and also you always can study open source libraries (like DotNetZip) – Eldarien Sep 07 '15 at 19:18
  • Thanks youu too man will try that too :-P and give you feedback – dotbot Sep 07 '15 at 19:23
0

As it sounds like you can use the classes provided in the .Net Framework, the MSDN documentation will be a good place to look - ZipFile Class

This code will extract the files from a given zip file:

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}
Stuart
  • 754
  • 11
  • 25
  • They were too slow or something idk – dotbot Sep 07 '15 at 19:13
  • 3
    If you have to write your own implementation of Zip format I very much doubt that it will be faster then Microsoft's implementation. – Eldarien Sep 07 '15 at 19:14
  • Any idea how to start writing this coz it's something new for me I need a way that I can start . – dotbot Sep 07 '15 at 19:16
  • I used this once but it was many years ago and so can't guarantee that it will still work - http://www.codeproject.com/Articles/18495/Simple-Application-to-Zip-and-UnZip-files-in-C-usi – Stuart Sep 07 '15 at 19:21
  • Thanks I will write to you tomorrow when I test it and try to get it on work :-P – dotbot Sep 07 '15 at 19:22
  • hello I try with the Windows Lib and it's too slow for now I will keep work on my own – dotbot Sep 08 '15 at 17:48
0

If you'd like to do your own unzipping, then you have to understand the .zip file format and all of the technologies that go into file compression and packaging.

This is a good place to start: https://en.wikipedia.org/wiki/Zip_%28file_format%29

Good luck! Zipping and unzipping is not simple!

LVBen
  • 2,041
  • 13
  • 27