Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys, Please I have an application that I have built and
is just sort of printing c# App,
First I populate ListBox and format it then goto c:\somefolder
in some folder are pdf files it looks on listbox and see if there is any file name that matches an item on the listbox and sends it to the default printer.
Everything is working great ,but say I have JohnDoe.pdf,ShahRukh.pdf,Vijay.pdf
how can I make it to send the files in that order, for now it works greatt ,but I want to be able to print ==> JohnDoe.pdf first, then ShahRukg.pdf and so on and so forth.Please if you have any idea to spare is much welcome.
Thanks in adavance.
Posted
Comments
Sergey Alexandrovich Kryukov 4-Mar-15 18:01pm    
So far, it makes no sense. When you say "this order", you should explain when "this order" comes from, what is the data source for that order. For example, you can put it in the list box in certain order, or drag items later. When, for example, the order of items in this control is set, it can be considered as required order, but then, how could traversing them in this order could possibly be a problem? In other words, what is the different order you don't like?
What idea it may possibly require? Just do it.
—SA
ChrisCreateBoss 4-Mar-15 18:41pm    
So you want to place each item in a custom order? That's what you want to do?

C#
private void btn_PrintMacro_Click(object sender, EventArgs e)
       {
          try
          {
               string dir = @"C:\slim\slimyyyy"

               if (Directory.Exists(dir))//If a directory defined above exists then do the followings
               {
                   string[] pdf_specFiles = Directory.GetFiles(dir);
                   if (pdf_specFiles.Length > 0)
                   {

                    //   foreach (string file in pdf_specFiles)
                       //{
                       //    string fileName = Path.GetFileName(file);
                           foreach (object item in listBox1.Items)
                         //  foreach (object line in rchTxtContent.Lines)
                           {
                               foreach (string file in pdf_specFiles)
                               {
                                   string fileName = Path.GetFileName(file);
                               if (fileName == item.ToString())

                               {
                                   PrintDocument(Path.GetFullPath(file));
                               }

                           }
                       }
                   }
               }
           }
           catch (Exception  )
           {
               MessageBox.Show("There is a possibility that one or more  of  Spec file - (s)  is not in the said Directory ok.");
           }
       }
 
Share this answer
 
Comments
ChrisCreateBoss 4-Mar-15 19:03pm    
With your current code, in which order is printing your app?
Ekona_Pikin 4-Mar-15 19:13pm    
It just prints randomly
some times it start in the middle, bottom and top,
I want it to have an order either from bottom to top or top to bottom
C#
   {

    var printList = new List();

    try
    {
        string dir = @"C:\slim\slimyyyy";
        if (Directory.Exists(dir))
        {
            string[] pdf_specFiles = Directory.GetFiles(dir);
            if (pdf_specFiles.Length > 0)
            {
                foreach (object item in listBox1.Items)
                {
                    foreach (string file in pdf_specFiles)
                    {
                        string fileName = Path.GetFileName(file);
                        if (fileName == item.ToString())
                        {
                            printList.Add(Path.GetFullPath(file));
                        }
                    }
                }

                foreach (string file in printList)
                {
                    PrintDocument(file);
                    System.Threading.Thread.Sleep(10000); // wait half a second say
                    Application.DoEvents(); // keep UI responsive if Windows Forms app
                }
            }
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show("" + ex);
    }
}>
 
Share this answer
 
v3

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