zip in vb.net

HalCHub
HalCHub used Ask the Experts™
on
I know how to add  a directory to an zip file but how to I add a file to an existing zip and how to I create a zip file with only item ?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Software Developer
Commented:
Use the DotNetZip library. It's very easy to use.

http://dotnetzip.codeplex.com/

Author

Commented:
I read thru it and I guess I am just dense and can not find my answer.

:(
Russ SuterSenior Software Developer

Commented:
            ZipFile zip = new ZipFile(@"D:\Temp\test.zip");
            zip.AddFile(@"D:\Temp\sad-face.jpg", @"\sad\");
            zip.Save();

Open in new window

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Russ SuterSenior Software Developer

Commented:
Or in VB.NET

Dim zip As New ZipFile("D:\Temp\test.zip")
zip.AddFile("D:\Temp\sad-face.jpg", "\sad\")
zip.Save()

Open in new window

Author

Commented:
my  zipfile object does not have an additem method.
Russ SuterSenior Software Developer

Commented:
That's an example using the DotNetZip library I provided a link for in the first post. The method is AddFile, not additem.

Author

Commented:
I miss typed... I dont have that method either

Author

Commented:
these samples target dotnet 2.0 and 3.0... most sites have dotnet 4.x
Russ SuterSenior Software Developer

Commented:
dotnet 4.x is backward compatible.

Make sure you have a reference to the correct library.

I dug up a stackoverflow article that addresses this. Interestingly, at the end of the article it uses basically the same code that I have provided above.

http://stackoverflow.com/questions/27009422/how-to-add-ionic-zip-dll-in-c-net-project-and-use-it-to-create-a-zip-from-folde

Author

Commented:
dotnet 4.5 is not backward compatible since it is missing most of the zipfile methods. https://msdn.microsoft.com/en-us/library/system.io.compression.zipfile(v=vs.110).aspx
Russ SuterSenior Software Developer

Commented:
Use the DotNetZip library I suggested in the first post. It's open source and with it you can do what you need to do in 3 lines of code. The library is compatible with .net 2.0 and up.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial