Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am doing a Restaurant management project.

I should be printing the bill and item ordered details.
There are two inkjet printers, one for printing kitchen ordered details in the kitchen and another for Bill printing in cashier counter.

I am creating prn file every time.
I want to print each file to the corresponding printer and so must give the printer a name.

How to do it?

Please any help for this problem

Thanking you
Posted
Updated 5-Jan-12 21:50pm
v2
Comments
Dalek Dave 6-Jan-12 3:50am    
Edited for Spelling, Grammar, Syntax and Clarity.

1 solution

You can use an ObjectQuery using System.Management to retrieve printers on the network, like this

C#
// Use the ObjectQuery to get the list of configured printers
            System.Management.ObjectQuery query =
                new System.Management.ObjectQuery("SELECT * FROM Win32_Printer");
 
            System.Management.ManagementObjectSearcher searcher =
                new System.Management.ManagementObjectSearcher(oquery);
 
            System.Management.ManagementObjectCollection collection = searcher.Get();
 
            foreach (ManagementObject mo in collection)
            {
                System.Management.PropertyDataCollection pdc = mo.Properties;
                foreach (System.Management.PropertyData pd in pdc)
                {
                    if ((bool)mo["Network"])
                    {
                        cmbPrinters.Items.Add(mo[pd.Name]);
                    }
                }
            }


Hope this helps
 
Share this answer
 
Comments
Dalek Dave 6-Jan-12 3:51am    
Nice answer.
Wayne Gaylard 6-Jan-12 3:54am    
Thanks!

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