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 void btn_trace_opendirectory_Click(object sender, EventArgs e) { try { // Opens explorer.exe to the trace directory Process prc = new Process(); prc.StartInfo.FileName = CrmTrace.GetTraceFolderPath(); prc.Start(); } catch (Exception error) { MessageBox.Show(this, "Error while opening trace directory: " + error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_trace_cleandirectory_Click(object sender, EventArgs e) { try { List <string> filesNotDeleted = new List <string>(); // Retrieving files in the specified trace directory DirectoryInfo di = new DirectoryInfo(CrmTrace.GetTraceFolderPath()); foreach (FileInfo fi in di.GetFiles()) { try { File.Delete(fi.FullName); } catch { filesNotDeleted.Add(fi.Name); } } // Displaying files not deleted because they are still in use // by some Crm service if (filesNotDeleted.Count > 0) { string message = "Some files were not deleted:\r\n" + string.Join("\r\n", filesNotDeleted); MessageBox.Show(this, message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { MessageBox.Show(this, "Trace directory cleaned!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception error) { MessageBox.Show(this, "Error while cleaning trace directory: " + error.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }