Click here to Skip to main content
15,179,246 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi,

My requirement is when i click on default crystal report print button, it will open printoptions window, when i select the Ok button, on button click event i want to insert data into the database(Call method). I have tried so many way but i did't get and then i have changed desgin like i have taken one dropdownlist to bind network printers and then when click on button it will insert data into the db and print starts.

C#
myReportDocument.PrintToPrinter(1, false, 1, 1);


But in local host it is working fine when i moved this to the server i am not able to get printers list. To get printer i have used following code.

First Method:
C#
var queues = server.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local,EnumeratedPrintQueueTypes.Shared,
     EnumeratedPrintQueueTypes.Connections});
            foreach (var printer in queues)
            {
                DdlPrinters.Items.Add(printer.Name);

            }

Second Method:

C#
foreach (var print in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
           {
               DdlPrinters.Items.Add(print);
           }

Third Method:
C#
System.Management.ObjectQuery oq = new System.Management.ObjectQuery
("SELECT * FROM Win32_PrintJob");
ManagementObjectSearcher query1 = new ManagementObjectSearcher(oq);
ManagementObjectCollection queryCollection1 = query1.Get();
foreach( ManagementObject mo in queryCollection1 )
{
}

Please suggest me how can i get network printers. Thanks in advance...
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900