我有一个复选框,其中包含一些exe /应用程序名称。当我要选择其中任何一个时,它应该开始。 现在应用程序正在启动,但是如果我从路径中不存在的复选框中选择了exe / application name(我在下面写了),即如何对其进行验证。我的代码是:
NoSuchKey
答案 0 :(得分:1)
string path = @"D:\Development\Latest\ConsoleApplication1\ConsoleApplication1\bin\Debug";
string files = Directory.GetDirectoryRoot(path);
var exeNotFoundList = new List<string>();
for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
{
var exeFilePathWithName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe");
if(!File.Exists(exeFilePathWithName))
{
exeNotFoundList.Add(exeFilePathWithName);
continue;
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = exeFilePathWithName
}
};
process.StartInfo.UseShellExecute = false;// Beacuse I am using Process class
process.StartInfo.CreateNoWindow = true;
process.Start();
}
if(exeNotFoundList.Count > 0)
{
var errorMessage = String.Join(String.Empty, exeNotFoundList.ToArray());
MessageBox.Show(errorMessage);
}