Reputation: 504
I have an application with WF control hosted in WPF window and i'm proceesing some record and playback actions in my project. I get the below exception while performing play back.
The system cannot find the file specified
I have searched regarding this and seen some suggestions that we need to provide the full path of the file to process.I have tried this also, but still i'm getting this exception.
Please anyone let me know how to resolve this?
var instance = testclass.GetControlForTest();
WindowsFormsHost host = new WindowsFormsHost();
host.Child = instance;
var testwindow = new TestWindow(testdata, testclass, false, (MainWindow)Application.Current.MainWindow, true);
testwindow.testSurface.Children.Add(host);
testwindow.Show();
await Task.Delay(1000);
Process p = new Process();
var mainPath = Directory.GetCurrentDirectory();
do
{
mainPath = Directory.GetParent(mainPath).FullName;
} while (Directory.GetParent(mainPath).Name != "WindowsForms_Testing");
var targetPath = mainPath + "\\exes\\" + "\\";
mainPath = Directory.GetParent(mainPath).FullName;
mainPath = mainPath + "\\TestStudio\\Syncfusion.TestVisualBase.WPF\\RecordAction\\RecordAction.WPF\\bin\\Debug\\RecordAction.WPF.exe";
p.StartInfo.FileName = mainPath.Replace("\\", "/");
p.StartInfo.Arguments = file; //("..//..//test.xml")
p.Start();
Thanks,
Upvotes: 1
Views: 2109
Reputation: 1444
p.StartInfo.FileName = mainPath.Replace("\\", "/");
, because windows use \
for pathesvar targetPath
ut do not use it in the future.@
for escaping cpecial-symbols, e.g. mainPath = mainPath + @"\TestStudio\Syncfusion.TestVisualBase.WPF\RecordAction\RecordAction.WPF\bin\Debug\RecordAction.WPF.exe";
Path.Combine()
methodp.StartInfo.FileName
must starts from disc name e.g. C:\
, or dot/s e.g. .\your_path
or ..\parent_directory\your_path
or starts from file or folder directly, relative current directory Directory.GetCurrentDirectory();
Upvotes: 1