zoukankan      html  css  js  c++  java
  • C# 打开指定目录并定位到文件

    1.

    打开文件夹:

    System.Diagnostics.Process.Start(FilePath);

    打开文件夹中某个文件:

    System.Diagnostics.Process.Start(FilePath+"/"+FileName);

    打开文件夹并选中单个文件:

    System.Diagnostics.Process.Start("Explorer", "/select,"+ FilePath+"\"+FileName);

    System.Diagnostics.Process.Start("Explorer.exe", "/select,"+ FilePath+"\"+FileName);

    用IE打开文件:

    System.Diagnostics.Process.Start("Explorer",FilePath+"\"+FileName);

    System.Diagnostics.Process.Start("Explorer.exe",FilePath+"\"+FileName);

    注:(explorer,explorer.exe,select,不区分大小写,”/selecet,”其中”/,”都不能少,FilePath为文件路径不包含文件名)

    扩展提示:可以采用 Application.StartupPath 获得应用程序所在的目录。

    2.

    C# 实现:

    1.  1  
       2 private void OpenFolderAndSelectFile(String fileFullName)
       3  
       4 {
       5  
       6 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
       7  
       8 psi.Arguments = "/e,/select," + fileFullName;
       9  
      10 System.Diagnostics.Process.Start(psi);
      11  
      12 }

    复制代码

    参考:

    Windows 资源管理器参数的用法。 

    Explorer /n
    此命令使用默认设置打开一个资源管理器窗口。显示的内容通常是安装 Windows 的驱动器的根目录。
    Explorer /e
    此命令使用默认视图启动 Windows 资源管理器。
    Explorer /e,C:Windows
    此命令使用默认视图启动 Windows 资源管理器,并把焦点定位在 C:Windows。
    Explorer /root, C:WindowsCursors
    此命令启动 Windows 资源管理器后焦点定位在 C:WindowsCursors folder。此示例使用 C:WindowsCursors 作为 Windows 资源管理器的“根”目录。
     

    备注:请注意命令中“/root”参数后面的逗号。

    Explorer /select, C:WindowsCursorsanana.ani
    此命令启动 Windows 资源管理器后选定“C:WindowsCursorsanana.ani”文件。

    备注:请注意命令中“/select”参数后面的逗号。
    Windows 资源管理器参数可以在一个命令中进行组合。以下示例显示了 Windows 资源管理器命令行参数的组合。
    Explorer /root, \servershare, select, Program.exe
    此命令启动 Windows 资源管理器时以远程共享作为“根”文件夹,而且 Program.exe 文件将被选中。
    回到顶端
    更改 Windows 资源管理器默认启动文件夹
    若要更改 Windows 资源管理器的默认启动文件夹,请:
    单击开始,指向所有程序,指向附件,然后右键单击Windows Explorer。
    在出现的菜单上,单击属性。
    在“目标”框中,将“/root”命令行参数附加到“%SystemRoot%Explorer.exe”命令之后,并使用您希望的启动位置。例如,如果您希望 Windows 资源管理器启动后定位在 C 驱动器的根,则请将该命令编辑为:
    %SystemRoot%Explorer.exe /root, C:

  • 相关阅读:
    设备arduino的编译目录
    c# await 关键字错误
    开篇 hello 内Cool超人
    在Windows Azure虚拟机上开发Windows 8 应用
    使用LVS实现负载平衡之Windows Server 2008配置
    IDC Digital Transition Annual Festival(2018.10.19)
    Dell Technology Summit(2018.10.17)
    Lean Data Innovation Sharing Salon(2018.09.15)
    Trusted Block Chain Summit(2018.10.09)
    Artificial Intelligence Computing Conference(2018.09.12)
  • 原文地址:https://www.cnblogs.com/singov/p/11855318.html
Copyright © 2011-2022 走看看