Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get print queue details for a shared printer

Am trying to print a document on a shared printer; i need to get print queue details.The following code always gets queue from 'Microsoft XPS Document' as Number of jobs=0.But my default printer is configured as 'HP LaserJet P1505n'

LocalPrintServer server = new LocalPrintServer()
PrintQueueCollection queueCollection = server.GetPrintQueues();
PrintQueue printQueue = null;
foreach (PrintQueue pq in queueCollection)
{
 Logger.LogInfo("PrintQueue1", "Printer1 Queue Name " + pq.FullName);
 printQueue = pq;
 numberOfJobs = printQueue.NumberOfJobs;
 Logger.LogInfo("numberOfJobs1"+ numberOfJobs);
}

How to get print queue details from that specific shared printer? i tried following also

PrintServer server = new PrintServer(@"\\192.168.100.168\HP LaserJet P1505n");

but got error as:

Win32 error: The filename, directory name, or volume label syntax is incorrect

What am i missing here?

like image 548
Murali Uppangala Avatar asked Dec 26 '22 17:12

Murali Uppangala


2 Answers

How to get print queue details from that specific shared printer?

Try something like this:

// string.Empty or null for local printers
string printServerName = @"\\server";
string printQueueName= "printer";

PrintServer ps = string.IsNullOrEmpty(printServerName)
    // for local printers
    ? new PrintServer()
    // for shared printers
    : new PrintServer(printServerName);
PrintQueue pq = ps.GetPrintQueue(printQueueName);

Console.WriteLine(pq.FullName);
Console.WriteLine(pq.NumberOfJobs);
// output is printer uri (\\server\printer) and 0.

Is also possible use server ip address (like string) instead server name.

string printServerName = @"\\192.168.1.111"; // for example

i.e
for local printer PDFCreator set

string printServerName = null;
string printerName = "PDFCreator";

and for shared printer P on server S set

string printServerName = @"\\S";
string printerName = "P";
like image 164
honzakuzel1989 Avatar answered Dec 28 '22 06:12

honzakuzel1989


System.Printing.PrintServer class documentation on MSDN

Try this:

var myServer = @"\\192.168.100.168";

With this code:

// Create a PrintServer
// "theServer" must be a print server to which the user has full print access.
// var myServer = @"\\theServer"
PrintServer myPrintServer = new PrintServer(myServer);

// List the print server's queues
PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
String printQueueNames = "My Print Queues:\n\n";
foreach (PrintQueue pq in myPrintQueues)
{
    printQueueNames += "\t" + pq.Name + "\n";
}
Console.WriteLine(printQueueNames);
Console.WriteLine("\nPress Return to continue.");
Console.ReadLine();
like image 24
JohnB Avatar answered Dec 28 '22 06:12

JohnB