Default printer setting using dot net
Posted on 8/10/2009 12:43:30 AM
in #Dot Net Framework
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.). /SPAN>/o:p>/SPAN>
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. /SPAN>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);/SPAN>/P>To use the code, you need to import the System.Runtime.InteropServices namespace as below.
using System.Runtime.InteropServices;/o:p>/SPAN>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;
/o:p>/SPAN>Vikram P.S. Thanks to Anindita for her Help with Code/o:p>/SPAN>/DIV>
|