Avatar of HalCHub
HalCHub
Flag 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
Visual Basic.NET

Avatar of undefined
Last Comment
Russ Suter

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Russ Suter

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
HalCHub

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

:(
Russ Suter

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

Open in new window

Russ Suter

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

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
HalCHub

ASKER
my  zipfile object does not have an additem method.
Russ Suter

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

ASKER
I miss typed... I dont have that method either
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
HalCHub

ASKER
these samples target dotnet 2.0 and 3.0... most sites have dotnet 4.x
Russ Suter

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
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Russ Suter

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.