c# - 在资源管理器中打开文件夹并选择文件

标签 c# explorer

我正在尝试在资源管理器中打开一个文件夹并选择了一个文件。

下面的代码会产生一个找不到文件的异常:

System.Diagnostics.Process.Start(
    "explorer.exe /select," 
    + listView1.SelectedItems[0].SubItems[1].Text + "\\" 
    + listView1.SelectedItems[0].Text);

如何让这个命令在 C# 中执行?

最佳答案

// suppose that we have a test.txt at E:\
string filePath = @"E:\test.txt";
if (!File.Exists(filePath))
{
    return;
}

// combine the arguments together
// it doesn't matter if there is a space after ','
string argument = "/select, \"" + filePath +"\"";

System.Diagnostics.Process.Start("explorer.exe", argument);

关于c# - 在资源管理器中打开文件夹并选择文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/334630/

相关文章:

c# - 抛出异常是一个好习惯吗?

c# - 在没有 Foreach 循环的情况下访问 LINQ 结果中的行?

svn - 有没有办法从 TortoiseSVN Explorer 图标装饰中排除 {ignore-on-commit} 更改?

资源管理器中未显示 CSS 图像

javascript - IE 上的按键事件序列

windows - 如果我为我的程序创建一个新的文件类型,我该如何正确使用 "Open With"?

C# 模拟 Windows 中的默认拖放功能(拖动过程中的透明图像)

c# - 创建模拟时如何组合两个接口(interface)?

c# - 如何将数字转换为泛型类型?

windows - 文件名包含两个空格的 exec.Command 失败