Chris <an*******@disc ussions.microso ft.com> wrote:
Thhats the same lib I downloaded but I can't seem to unzip a .zip
file. Do you have any ideas?
Well, using ZipFile, ZipInputStream and ZipEntry seem to be a good bet
to me.
I've just written this code which unzips a file - but it doesn't do
anything about paths etc, so will fail on various zip files. It just
demonstrates the very basic ideas.
using System.IO;
using ICSharpCode.Sha rpZipLib.Zip;
public class Test
{
static void Main(string[] args)
{
foreach (string x in args)
{
Unzip (x);
}
}
static void Unzip (string zipName)
{
byte[] buffer = new byte[16384];
ZipFile zipFile = new ZipFile(zipName );
try
{
foreach (ZipEntry entry in zipFile)
{
Stream input = zipFile.GetInpu tStream(entry);
using (Stream output = File.Create(ent ry.Name))
{
int read;
while((read=inp ut.Read(buffer, 0,buffer.Length ))>0)
{
output.Write(bu ffer, 0, read);
}
}
}
}
finally
{
zipFile.Close() ;
}
}
}
--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too