Solved

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

Posted on 2006-11-05
1
1,917 Views
Last Modified: 2009-06-03
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
Comment
Question by:vikasbapat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
Expert1701 earned 500 total points
ID: 17879147
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question