Solved

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

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

12 Experts available now in Live!

Get 1:1 Help Now