Default printer setting using dot net
Hi,

There came a requirement in one of my colleague’s project whereby it was needed to set the printer to be used for the lotus notes (The project is about integrating with Lotus Notes.).  

To solve the issue instead of looking into the Lotus notes API I thought it should be much easy to set the default printer for the machine. Once the Default printer is set Lotus notes will use this printer to print any document.  Below is the code needed to set the default printer of any machine.

[DllImport("winspool.drv", SetLastError = true)]
private static extern void SetDefaultPrinter(string name);

To use the code, you need to import the System.Runtime.InteropServices namespace as below.

using System.Runtime.InteropServices;
You might also require to find the default printer in the machine. For that the code is given below.

System.Drawing.Printing.PrinterSettings oPS = new System.Drawing.Printing.PrinterSettings();
functionReturnValue = oPS.PrinterName;

Vikram
P.S. Thanks to Anindita for her Help with Code

Share this post   Email it

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 

Copyright © 2006 - 2010 Vikram Lakhotia