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 42 43 44 45 46 47 48 49 50
|
public void decompression(string destinationDirectory, string myzipfile)
{
try
{
// ouvre le fichier zip
FileStream zipFilePath = new FileStream(myzipfile, FileMode.Open, FileAccess.Read);
ZipInputStream s = new ZipInputStream(zipFilePath);
// output path
String outputPath = destinationDirectory;
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = System.IO.Path.GetDirectoryName(theEntry.Name);
string fileName = System.IO.Path.GetFileName(theEntry.Name);
Directory.CreateDirectory(outputPath + directoryName);
if (fileName != String.Empty)
{
FileStream streamWriter = File.Create((outputPath + theEntry.Name));
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
streamWriter.Close();
}
}
s.Close();
// Message
/*String msg = String.Format("Le fichier zip a été décompressé dans le répertoire {0}", outputPath);
System.Windows.MessageBox.Show(msg);*/
}
catch (Exception exception)
{
MessageBox.Show("Erreur lors de la décompression de maj.zip, le fichier a t'il était télécharger ? | " + exception);
}
} |
Partager