コード例 #1
0
        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)
                {
                    NtoNTransportImportFailuresReportViewer tifrv = new NtoNTransportImportFailuresReportViewer(reportFailuresFileName);
                    tifrv.Show();
                }

                else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
                {
                    Console.WriteLine(ex.Message + ". You do not have permission to access this report file.");
                }
            }
        }
コード例 #2
0
        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)
                {
                    NtoNTransportImportFailuresReportViewer tifrv = new NtoNTransportImportFailuresReportViewer(reportFailuresFileName);
                    tifrv.Show();
                }

                else if (ex.NativeErrorCode == ERROR_ACCESS_DENIED)
                {
                    Console.WriteLine(ex.Message + ". You do not have permission to access this report file.");
                }
            }
        }