How do I open a exe in a parent folder?
An example would be
Debug\Folder1\Folder2
There is an exe in folder2 and folder1
I want it so when I click button with the exe in folder2 it opens up a exe in folder1
CodePudding user response:
private void OpenEXE_BtnClick(object sender, RoutedEventArgs e)
{
var currentFolder = Directory.GetCurrentDirectory();
var parentFolder = Path.GetDirectoryName(currentFolder);
var exeFile = Path.Combine(parentFolder, "{FileName}");
try
{
using (Process myProcess = new Process())
{
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = exeFile;
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
}
}
catch (Exception ex)
{
//Console.WriteLine(ex.Message);
MessageBox.Show(
"Some thing happend when trying run background backup!!" Environment.NewLine ex.Message,
"Running Background Backup", MessageBoxButton.OK, MessageBoxImage.Error);
}
}