• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1948
  • Last Modified:

How to Print to non Default Printer in c#.net?

Hi,

I want to print a Word document to the printer which user is going to select using dropdown box.

So my Question is "How to Print to non Default Printer in c#.net 2005 ?"
Currently it is printing to the default printer so is there any way to change the
default printer through code.

Thanks in Advance.
Manoj.
0
vikasbapat
Asked:
vikasbapat
1 Solution
 
Expert1701Commented:
Here is a method to change the default printer in Windows:

  void SetDefaultPrinter(string name)
  {
     try
     {
        Type t = Type.GetTypeFromProgID("WScript.Network");
        Object o = Activator.CreateInstance(t);
        t.InvokeMember("SetDefaultPrinter", System.Reflection.BindingFlags.InvokeMethod, null, o, new object[] {name});
     }
     catch (Exception)
     {
        throw new Exception("Unable to set a default printer. The printer may not exist or the WScript.Network com object may have a problem.");
    }
  }

Source: (http://www.nullify.net/ViewArticle.aspx?article=247)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now