Printing a file using process object
-
HI, Iam tring to print a file(can be word, excel, visio, etc) through c#. i have used the process and process start info objects and could complete the task bu the constraint is while printing the original file is being opened! Let us say for example iam printing document1.doc through the code then the document1 is opened first then printing is done at the background, after the completion of printing the document1 is closed by itself. is there a procedure for me to change this behaviour?
gauthee
-
HI, Iam tring to print a file(can be word, excel, visio, etc) through c#. i have used the process and process start info objects and could complete the task bu the constraint is while printing the original file is being opened! Let us say for example iam printing document1.doc through the code then the document1 is opened first then printing is done at the background, after the completion of printing the document1 is closed by itself. is there a procedure for me to change this behaviour?
gauthee
gauthee wrote:
i have used the process and process start info objects and could complete the task bu the constraint is while printing the original file is being opened!
You mean is opened in Word of Excel, etc? If so, one solution would be to wait until the file has been sent to the printer(by periodically checking the number of print jobs) and after that close the main application. The first part can be achieved with this(code suggested by Martin#):
ObjectQuery qry = new ObjectQuery("SELECT * FROM Win32_PrintJob"); ManagementObjectSearcher srchr = new ManagementObjectSearcher(qry); ManagementObjectCollection coll = srchr.Get(); int initialJobs = coll.Count; while (coll.Count == initialJobs) { System.Threading.Thread.Sleep(10); coll = srchr.Get(); }
Good luck!