1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| private void ExtractZip(string zipFilename, string extractDir)
{
try
{
ICSharpCode.SharpZipLib.Zip.ZipInputStream zis = null;
FileStream fos = null;
zis = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(new FileStream(zipFilename, FileMode.Open, FileAccess.Read));
ICSharpCode.SharpZipLib.Zip.ZipEntry ze;
while ((ze = zis.GetNextEntry()) != null)
{
if (ze.IsDirectory)
{
Directory.CreateDirectory(extractDir + "\\" + ze.Name);
}
else
{
if (!Directory.Exists(extractDir + "\\" + Path.GetDirectoryName(ze.Name)))
{
Directory.CreateDirectory(extractDir + "\\" + Path.GetDirectoryName(ze.Name));
}
fos = new FileStream(extractDir + "\\" + ze.Name, FileMode.Create, FileAccess.Write);
int count;
byte[] buffer = new byte[4096];
while ((count = zis.Read(buffer, 0, 4096)) > 0)
{
fos.Write(buffer, 0, count);
}
fos.Close();
}
}
}
catch (Exception e)
{
}
} |
Partager