vendredi 22 mai 2015

Compare Listbox item(s) with available exe files in (D:) drive of PC

I have one check box which contains some exe/application names. When i am going to select any one of them then it should start. Now application is starting but if i have selected exe/application name from check box which does not exists in path(which i have written below) .ie. how to put validation on that my code is:

 if (chkListBox.CheckedItems.Count > 0)
            {
                for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
                {
                    string path = @"D:\Development\Latest\ConsoleApplication1\ConsoleApplication1\bin\Debug";
                    string files = Directory.GetDirectoryRoot(path);
                    var process = new Process
                    {
                        StartInfo = new ProcessStartInfo
                        {
                            FileName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe")
                        }
                    };

                    process.StartInfo.UseShellExecute = false;// Beacuse I  am using Process class
                    process.StartInfo.CreateNoWindow = true;
                    process.Start();


                }
            }
            else
            {
                MessageBox.Show("Item Not  selected");
            }




Aucun commentaire:

Enregistrer un commentaire