public static void execute(string[] filesToExecute, string recipient, string from, string credentials) { if (filesToExecute.Count() > 0) { foreach (string batchName in filesToExecute) { string filenew = Directory.GetCurrentDirectory(); string happy = filenew + "\\Mohit"; if (!Directory.Exists(happy)) { Directory.CreateDirectory(happy); } else { Directory.Delete(happy, true); System.Threading.Thread.Sleep(2000); Directory.CreateDirectory(happy); } try { InitiateClassforsearch.func(batchName, happy, true); } catch (Exception w) { //// do nothing } try { string[] happyfiles = Directory.GetFiles(happy); string subject = "Trigger batch Successfully searched batch files, total " + happyfiles.Count() + " files found" + "we will execute file in QA Automation Framework, if QA Automation Frameword don't have any such file, we will execute any one available, execution results will be shared shortly"; SendMail.SendEmail(recipient, subject, subject, from, credentials); foreach (string file in happyfiles) { ArrayList list = new ArrayList(); string[] files = file.Split('_'); foreach (string splited in files) { list.Add(splited); } if (list.Contains("QaAutomationFramework")) { Process proc = new Process(); proc.StartInfo.FileName = file; proc.StartInfo.UseShellExecute = true; proc.Start(); break; } else { Process proc = new Process(); proc.StartInfo.FileName = happyfiles[0]; proc.StartInfo.UseShellExecute = true; proc.Start(); break; } } } catch (Exception w) { //// do nothing } } } }