System.Diagnostics.Process.Start "Cannot find a specific file" problem

When I run the following code on my computer, it works fine

string target = e.Link.LinkData as string;
target = System.IO.Directory.GetCurrentDirectory() + target;
System.Diagnostics.Process.Start(target);

target is not an absolute file path. Files exist. When clearing a virtual machine exception "Cannot find a specific file."

Any suggestions?
Update
I emphasize that it works fine on my computer. Why it does not work on another computer.

+3
source share
5 answers

The first thing I would like to do to try to figure this out is to check the exact path that is reported when it fails.

- ( , Path.Combine, ):

string target = e.Link.LinkData as string;
target = Path.Combine(System.IO.Directory.GetCurrentDirectory() + target);
var fileInfo = new FileInfo(target);
if (!fileInfo.Exists)
{
    throw new FileNotFoundException("The requested file was not found: " + fileInfo.FullName);
}
System.Diagnostics.Process.Start(target);

, . , ?

- .

, , . , , , ?

...

+2
+7

GetCurrentDirectory() "\" . , .

+1

, DLL ? EXE Dependency Walker, , - ( ).

, MSDN Process.Start , ProcessStart FileNotFoundException, PATH , .

+1

procmon, , , , , Path.Combine .

, , dev?

0

Source: https://habr.com/ru/post/1732863/


All Articles