private void btn_trace_zipfiles_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = "Archive file (*.zip)| *.zip", InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) }; if (saveFileDialog.ShowDialog() == DialogResult.OK) { try { ZipManager zManager = new ZipManager(); zManager.CompressFolder(CrmTrace.GetTraceFolderPath(), saveFileDialog.FileName); MessageBox.Show(this, "Zip file created successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception error) { MessageBox.Show(this, "Error while creating zip file: " + error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private static FileInfo BackupFiles(DirectoryInfo pathToBackup, DirectoryInfo destinationDirectory, string destinationBackupName) { //Creo la directory dove sarà depositato il file di backup destinationDirectory.Create(); //Definisco dove sarà copiato lo zip di backup var destinationZipFile = new FileInfo(Path.Combine(destinationDirectory.FullName, destinationBackupName)); //Effettuo lo zip della cartella ZipManager.CompressFolder(pathToBackup, destinationZipFile); //Ritorno il FileInfo dello zip return(destinationZipFile); }