我有一个应用程序启动与该应用程序位于同一文件夹中的可执行文件,方法是:
Process procStarter = new Process(); procStarter.StartInfo.FileName = "OtherApp.exe"; procStart.Start();这工作正常,直到我在我的应用程序中使用文件打开或文件保存对话框。 然后它找不到OtherApp.exe。
这看起来很正常吗? 我可以通过将当前文件夹添加到StartInfo.Filename(以及如何获取当前文件夹)来修复它?
I have an app launching an executable which is in the same folder as that app, by doing:
Process procStarter = new Process(); procStarter.StartInfo.FileName = "OtherApp.exe"; procStart.Start();which works fine, until I used a file open or file save dialog in my app. Then it can't find OtherApp.exe.
Does that seem normal? Can I just fix it by adding the current folder to StartInfo.Filename (and how do I obtain the current folder)?
最满意答案
使用文件对话框可能会更改进程的当前目录。 要访问与当前可执行文件相同的文件夹中的文件,可以使用以下代码:
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); path = Path.Combine(path, "OtherApp.exe");Using the file dialog probably changes the current directory of your process. To access a file in the same folder as your current executable you can use the following code:
string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); path = Path.Combine(path, "OtherApp.exe");更多推荐
发布评论