Click here to Skip to main content
15,904,653 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

Sorry let me try improve my question here a bit. First a sample of my current code then i will ask what i need to ask.

C#
private void button2_Click(object sender, EventArgs e)
        {
            string cmdInput;
            string cmdPre;
            int index;
            string item;
            string selectedText;
            string server;
            int index1;
            string item1;


            index = listBox2.SelectedIndex;
            item = listBox2.Items[index].ToString();
            selectedText = item;

            index1 = listBox1.SelectedIndex; ;
            item1 = listBox1.Items[index1].ToString();

            //Creates localprintserver where the queue's can be created on
            LocalPrintServer localPrintServer = new LocalPrintServer();
            PrintQueueCollection myPrintQueues = localPrintServer.GetPrintQueues();
            
            //Need to add the items to a string or array or something so i can check                            if printer exists
            foreach (PrintQueue pq in myPrintQueues)
            {
               // Add items variable
            }


            //string myPrintQueues = PrinterSettings.InstalledPrinters.ToString();

            if (item1.Contains("Solution Worx - HQ"))
            {
                //string myPrintQueues = PrinterSettings.InstalledPrinters.ToString();

                if (myPrintQueues.Contains(selectedText))
                {

                    server = @"\\srvswx.swxhq.local\";

                    cmdPre = @"RunDll32.EXE printui.dll,PrintUIEntry /dn /q /n " + server;
                    cmdInput = selectedText;
                    ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd", "/c " + cmdPre + cmdInput);
                    Process process = Process.Start(processStartInfo);
                }
                else
                {
                    MessageBox.Show("The print queue you have selected is not installed on your PC");
                }
            }


So this is my code. I have 2 list boxes the one on the left the users selects his location and the one on the right they select the print queue on the server. Now my problem is when they press the 'remove' button i need to check if that printer exists and if it exists it removes the printer and if not it provides them with an error msg. There is unfortunately not much documentation on what i am trying to achieve.
Posted
Updated 25-Sep-14 20:26pm
v2
Comments
KaushalJB 25-Sep-14 8:15am    
You must rather build your code and press F5 and debug to check. Question your code not your logics :)
Ivan Lubbe 25-Sep-14 8:24am    
I am not receiving any sort of errors
[no name] 25-Sep-14 8:28am    
You can always just go read the documentation and find out what kind of collection it is. Or you can debug your code and find out that way too.
Ivan Lubbe 25-Sep-14 8:36am    
Well unfortunately there is no real documentation that i can find on this. All i know is its a collection of objects?
Ivan Lubbe 25-Sep-14 8:40am    
Perhaps ill need to add the collection to an array first ?

1 solution

You should debug and then use the Watch window or other debug tools to see exactly what you get. However, here is the documentation that should help you:

http://msdn.microsoft.com/en-us/library/system.printing.printqueuecollection(v=vs.110).aspx[^] and it has sample code at the bottom.
 
Share this answer
 
Comments
Ivan Lubbe 26-Sep-14 4:26am    
Hey Ryan, I am unable to find any information that helps me. I have been through so much documentation. But am unable to get this working.
ZurdoDev 26-Sep-14 7:20am    
That link shows how to loop through the list.
Ivan Lubbe 29-Sep-14 3:07am    
The problem i have is that i don't know how to work with that list. I need to do something like if (PrinterHP4300 exists) { then do this } else { do this }

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