Torna al Thread
public static bool Comprimi(string[] filesSorgenti, string fileDestinazione)
{
bool ris = true;
try
{
using (ZipOutputStream zipStream = new ZipOutputStream(File.Create(fileDestinazione)))
{
zipStream.SetLevel(7); //---- mah metto 7 pero' posso mettere tra 0-9
foreach (string f in filesSorgenti)
{
try
{
//--- meglio usare using cosi' viene distrutto l'oggetto quando finito
using (FileStream fs = new FileStream(f,FileMode.Open,FileAccess.Read))
{
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
ZipEntry entry = new ZipEntry(Path.GetFileName(f));
zipStream.PutNextEntry(entry);
zipStream.Write(buffer, 0, buffer.Length);
}
}
catch (Exception ex)
{
....
}
}
zipStream.Finish();
zipStream.Close();
}
}
catch
{
ris = false;
}
return ris;
}