Пример #1
0
        /// <summary>
        /// Prints the document file.
        /// </summary>
        /// <param name="filePath">File path of document to be printed.</param>
        public void PrintDocumentFile(string filePath)
        {
            bool   retVal    = false;
            bool   returnVal = false;
            string errMsg    = string.Empty;
            string dat       = string.Empty;

            //System.Diagnostics.ProcessStartInfo psi = new
            //System.Diagnostics.ProcessStartInfo();
            Process proc = new Process();

            const string MethodName =
                "public void PrintDocumentFile(string filePath)";

            MyMessages myMsg = new MyMessages();

            try
            {
                returnVal = File.Exists(filePath);

                if (!returnVal)
                {
                    errMsg = "File path for file to be printed is invalid." +
                             " Exit printing.";
                    myMsg.BuildErrorString(ThisClassName, MethodName, errMsg,
                                           dat);
                    return;
                }

                proc.StartInfo.FileName        = filePath;
                proc.StartInfo.UseShellExecute = false;
                //proc.RedirectStandardOutput = true;

                proc.StartInfo.Arguments = "lpr";
                //proc.Arguments = "test";
//				System.Diagnostics.Process p =
//					System.Diagnostics.Process.Start(proc);
                //p.WaitForExit();
                retVal = proc.Start();

                //retVal = p.ExitCode;

                if (retVal == false)
                {
                    errMsg = "Error unable to print. Is your printer on." +
                             " Is the linux package lpr installed.";
                    myMsg.BuildErrorString(ThisClassName, MethodName, errMsg,
                                           dat);
                    return;
                }
            }
            catch (ArgumentNullException ex)
            {
                errMsg = "File path for file to be printed is invalid." +
                         " Exit printing.";
                myMsg.BuildErrorString(ThisClassName, MethodName, errMsg,
                                       ex.ToString());
                return;
            }
            catch (InvalidOperationException ex)
            {
                errMsg = "File path for file to be printed is invalid." +
                         " Exit printing.";
                myMsg.BuildErrorString(ThisClassName, MethodName, errMsg,
                                       ex.ToString());
                return;
            }
        }