Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Printing a file using process object

Printing a file using process object

Scheduled Pinned Locked Moved C#
csharptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gauthee
    wrote on last edited by
    #1

    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

    B 1 Reply Last reply
    0
    • G 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

      B Offline
      B Offline
      blackjack2150
      wrote on last edited by
      #2

      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!

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups