OpenExplorerAndSelectFile

OpenExplorerAndSelectFile

本文介绍了在Windows资源管理器中打开一个文件夹,然后选择一个文件只能第二次使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

使用SO的此答案中描述的代码,我创建了以下功能:

Using the code described in this answer of the SO posting "Open folder and select the file", I've created this function:

public static void OpenExplorerAndSelectFile(string filePath)
{
    Process.Start(
        @"explorer.exe",
        string.Format(@"/select, ""{0}""", filePath));
}

此功能运行良好,存在一个小问题:

This function works well, with one small issue:

再次为同一文件调用相同的功能,它将切换回Windows资源管理器中已经打开的文件夹,然后选择该文件.

Calling the same function again for the same file, it switches back to the already open folder in Windows Explorer and then it selects the file.

例如第一次调用OpenExplorerAndSelectFile("C:\MyFolder\MyFile.txt")会在新的Windows资源管理器窗口中打开文件夹"C:\ MyFolder".实际上,第二次调用OpenExplorerAndSelectFile("C:\MyFolder\MyFile.txt")会再次激活该窗口并选择MyFile.txt.

E.g. the first call to OpenExplorerAndSelectFile("C:\MyFolder\MyFile.txt") opens the folder "C:\MyFolder" in a new Windows Explorer Window. The second call to OpenExplorerAndSelectFile("C:\MyFolder\MyFile.txt") actually activates that Window again and selects MyFile.txt.

做类似的事情实际上,在第一次尝试中,Google Chrome浏览器(转到下载页面并显示以前下载的文件)效果很好.

Doing something similar in e.g. Google Chrome (Going to the download page and showing a previously downloaded file) actually works well right in the first try.

所以我的结论是,谷歌浏览器似乎和我做的有点不同.

So my conclusion is that Google Chrome seems to do it a bit different than I do.

我的问题:

是否可以调试/跟踪Google Chrome调用的Win32/Shell方法?

Is there a way to debug/trace the Win32/Shell method that Google Chrome calls?

然后我将它们与我所做的比较以查看差异.

I would then compare them to what I do to see the differences.

推荐答案

Chrome最有可能使用更灵活的 SHOpenFolderAndSelectItems Shell API.

Rather than the explorer command line Chrome most probably uses the more flexible SHOpenFolderAndSelectItems Shell API.

此答案包含必需的p/invoke/implementation.

This answer contains the required p/invoke/implementation.

这篇关于在Windows资源管理器中打开一个文件夹,然后选择一个文件只能第二次使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 01:58