I need to input the file location from OpenFileDialog, as an argument to a .exe file, the problem is the file name has spaces and when they are called by the exe file as arguments, it breaks up on the spaces. For example if I where to get "C:\Users\Target Files\singlefile.txt", the string would be split between "Target" and "File"
private static void CreateBinFromHex(String pathToHexFile)
{
// Use ProcessStartInfo class
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.FileName = System.IO.Directory.GetCurrentDirectory() + "\\hex2bin.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = pathToHexFile;
try
{
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
catch(SystemException e)
{
MessageBox.Show(e.Message);
}
}
I tried different combinations in the terminal and found that enclosing the argument in a single quotes allows for a string including spaces to be used, but I cannot find a way to apply that in my program. For example---> the.exe 'C:\Users\Target Files\singlefile.txt' works perfectly.