private void failuresReportToolStripMenuItem_Click(object sender, EventArgs e) { //Check if the file exist if (!File.Exists(reportFailuresFileName)) { MessageBox.Show("Report File not found!"); return; } // These are the Win32 error code for file not found or access denied. const int ERROR_FILE_NOT_FOUND = 2; const int ERROR_ACCESS_DENIED = 5; try { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "EXCEL.EXE"; startInfo.Arguments = reportFailuresFileName; Process.Start(startInfo); } catch (Win32Exception ex) { if (ex.NativeErrorCode == ERROR_FILE_NOT_FOUND) { TransportImportFailuresReportViewer tifrv = new TransportImportFailuresReportViewer(reportFailuresFileName); tifrv.Show(); } else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED) { Console.WriteLine(ex.Message + ". You do not have permission to access this report file."); } } }
private void buttonFailuresReport_Click(object sender, EventArgs e) { //Check if the file exist if (!File.Exists(reportFailuresFileName)) { MessageBox.Show("Report File not found!"); return; } // These are the Win32 error code for file not found or access denied. const int ERROR_FILE_NOT_FOUND = 2; const int ERROR_ACCESS_DENIED = 5; try { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "EXCEL.EXE"; startInfo.Arguments = reportFailuresFileName; Process.Start(startInfo); } catch (Win32Exception ex) { if (ex.NativeErrorCode == ERROR_FILE_NOT_FOUND) { TransportImportFailuresReportViewer tifrv = new TransportImportFailuresReportViewer(reportFailuresFileName); tifrv.Show(); } else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED) { Console.WriteLine(ex.Message + ". You do not have permission to access this report file."); } } }