C# how do i printer status

Jordan Halgunseth 1 Reputation point
2023-03-13T15:24:29.7033333+00:00

How do I get print status.

I would like to if it is offline before print.

This code works after error.

  string printerinUse = pDialog.PrinterSettings.PrinterName;

                var server = new LocalPrintServer();

                PrintQueue queue = server.GetPrintQueue(printerinUse);

                MessageBox.Show("printer " + printerinUse +" is   " + queue.IsOffline.ToString());

                //various properties of printQueue
                bool isOutOfPaper = queue.IsOutOfPaper;
                bool isOffLine = queue.IsOffline;
                bool isPaperJam = queue.IsPaperJammed;
                bool isNotResponding = queue.IsInError;

                MessageBox.Show("printer " + printerinUse + " is   " + isNotResponding.ToString());

             

                if (isOffLine)
                {

                    MessageBox.Show("Printer is offline");
                    return;

                }
                if (isOutOfPaper)
                {

                    MessageBox.Show("Printer is out of paper");
                    return;

                }
                if (isPaperJam)
                {

                    MessageBox.Show("Printer has a paper jam");
                    return;

                }
                if (isNotResponding)
                {

                    MessageBox.Show("Printer is in error");
                    return;

                }
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,516 questions
{count} votes