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

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


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.
1 Solution
Here is a method to change the default printer in Windows:

  void SetDefaultPrinter(string name)
        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)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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