Solved

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

Posted on 2006-11-05
1
1,886 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now