简体   繁体   中英

how to open file from a folder with same name in C#

I need to run an executable file(Temp.exe) from "C:Program Files\\First Flight\\Temp Client" folder. The folder contains files with similar name as TempClientSetup.exml

I have this code

var path = @"C:\Program Files\First Flight\Temp Client";
var exepath = Path.Combine(Path.GetDirectoryName(path), "Temp.exe");
app = Application.Launch(exepath);

When I run this code, TempClientSetup.exml file is executed instead of Temp.exe

Any clues here? Pl suggest.

Stick a slash on the end of the path, or get rid of the Path.GetDirectoryName call.

var path = @"C:\Program Files\First Flight\Temp Client\";
var exepath = Path.Combine(Path.GetDirectoryName(path), "Temp.exe");

or

var path = @"C:\Program Files\First Flight\Temp Client";
var exepath = Path.Combine(path, "Temp.exe");

Here is the solution to my question for those who face this issue is, You may have to set the working directory of that exe to launch ;-) like this

var psi = new ProcessStartInfo(@"Temp.exe");
psi.WorkingDirectory = @"C:\Program Files\First Flight\Temp Client";            
app = Application.Launch(psi);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM