Hello,
I am trying to develop a Print Management System. The basic idea behind
this application is that, there are list of documents that needs to be
printed at a specified printer and we need to keep a watch on how the
printing is being carried out to get the status of the job.
Till now I was able to get the following things done,
1) Send document for printing to a specified printer
2) Add EventWatcher's to the print queue, that will keep a watch on a)
what new jobs are being added b) jobs being modified c) jobs deleted
I submit a job for printing to the printer queue by making use of the following
Process objProcess = new Process();
try
{
AddPrinterConnection(@"HP Deskjet D1300 Series");
SetDefaultPrinter(@"HP Deskjet D1300 series");
objProcess.StartInfo.FileName = "D:\\Remote Printing Management\\1.txt";
objProcess.StartInfo.Verb = "Print";
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
objProcess.StartInfo.UseShellExecute = true;
objProcess.Start();
}
catch (Exception ex)
{
//Exception caught
}
finally
{
objProcess.Close();
}
And in the eventwatcher's I am able to get the appropriate events.
But the problem I am facing now is that, When i submit the job for
printing as shown above, I need to find some way to get the jobid of
the printjob so that I can identify the job properly and update some
status in my database. Can somebody throw some light on this? Any help
would be greatly appreciated.
Thanks in advance!
Loading
naura paxPosted Nov 3, 2009, 1:25 AM
I would like to know can you store objProcess.Id (process id) in your database as Job ID, because process id is id for actuall process in your machine,
or else you can set objProcess.ProcessName as your filename and use that as id in your database.
apart from that you can update database right after Start() method,
in the following events
// these two events can be set right after declaring objProcess.
objProcess.ErrorDataReceived += new System.Diagnostics.DataReceivedEventHandler(p_ErrorDataReceived);
objProcess.Exited += new EventHandler(p_Exited);
void objProcess_Exited(object sender, EventArgs e)
{
throw new Exception("The method or operation is not implemented.");
}
void objProcess_ErrorDataReceived(object sender, System.Diagnostics.DataReceivedEventArgs e)
{
MessageBox.Show(e.Data);
}
In these two events you can update database by accessing ((Process)sender).ProcessName (or Id). along with e.Data in case of error.
Hope i am close to your solution.