Link to home
Start Free TrialLog in
Avatar of HalCHub
HalCHubFlag for United States of America

asked on

zip in vb.net

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
ASKER CERTIFIED SOLUTION
Avatar of Russ Suter
Russ Suter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HalCHub

ASKER

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

:(
Avatar of Russ Suter
Russ Suter

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

Open in new window

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

Avatar of HalCHub

ASKER

my  zipfile object does not have an additem method.
That's an example using the DotNetZip library I provided a link for in the first post. The method is AddFile, not additem.
Avatar of HalCHub

ASKER

I miss typed... I dont have that method either
Avatar of HalCHub

ASKER

these samples target dotnet 2.0 and 3.0... most sites have dotnet 4.x
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
Avatar of HalCHub

ASKER

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
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.