我看到了另一个话题,我有另一个问题.该过程正在启动(在任务管理器中看到),但文件夹未在我的屏幕上打开.怎么了?
System.Diagnostics.Process.Start("explorer.exe", @"c:\teste");
Run Code Online (Sandbox Code Playgroud)
Fre*_*örk 243
你确定文件夹" c:\teste"存在吗?如果没有,资源管理器将打开显示一些默认文件夹(在我的情况下为" C:\Users\[user name]\Documents").
更新
我尝试了以下变化:
// opens the folder in explorer
Process.Start(@"c:\temp");
// opens the folder in explorer
Process.Start("explorer.exe", @"c:\temp");
// throws exception
Process.Start(@"c:\does_not_exist");
// opens explorer, showing some other folder)
Process.Start("explorer.exe", @"c:\does_not_exist");
Run Code Online (Sandbox Code Playgroud)
如果这些都没有(除了抛出异常的那个)在你的计算机上运行,我认为问题不在于代码,而是在环境中.如果是这种情况,我会尝试以下一个(或两个):
Ore*_*ost 43
为了完整起见,如果你想要打开一个文件夹,请使用:
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() {
FileName = "C:\\teste\\",
UseShellExecute = true,
Verb = "open"
});
Run Code Online (Sandbox Code Playgroud)
此解决方案不适用于打开文件夹和选择项目,因为似乎没有动词.
Scy*_*ion 16
如果要选择文件或文件夹,可以使用以下命令:
Process.Start("explorer.exe", "/select, c:\\teste");
Run Code Online (Sandbox Code Playgroud)
使用非转义字符串时不需要双反斜杠:
System.Diagnostics.Process.Start("explorer.exe",@"c:\teste");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
197158 次 |
| 最近记录: |