打开文件夹
Opening Folders
我正在使用此代码打开一个文件夹:
If File.Exists(fileNameAndPath) Then
Process.Start("explorer.exe", Path.GetDirectoryName(fileNameAndPath))
End If
但是此代码不断打开同一文件夹的新 windows。
如何检查文件夹是否先打开然后打开它。如果文件夹已经打开,那么就把它放在前面?
是否可以突出显示我的文件存在?
我正在使用 .NET 2
谢谢
迭代打开资源管理器windows是可以的,你必须使用ShellWindows object。开始项目 > 添加引用 > 浏览 > select c:\windows\system32\shdocvw.dll
这样使用:
Public Shared Sub OpenExplorerWindow(ByVal fileNameAndPath As String)
Dim folder = System.IO.Path.GetDirectoryName(fileNameAndPath)
Dim target As New Uri("file://" + folder)
Dim windows As New SHDocVw.ShellWindows
For Each win As SHDocVw.InternetExplorer In windows
Dim loc As New Uri(win.LocationURL)
If loc.Equals(target) Then
SetForegroundWindow(New IntPtr(win.HWND))
Exit Sub
End If
Next
Process.Start("explorer.exe", folder)
End Sub
Private Declare Function SetForegroundWindow Lib "user32.dll" (hWnd As IntPtr) As Boolean
我正在使用此代码打开一个文件夹:
If File.Exists(fileNameAndPath) Then
Process.Start("explorer.exe", Path.GetDirectoryName(fileNameAndPath))
End If
但是此代码不断打开同一文件夹的新 windows。 如何检查文件夹是否先打开然后打开它。如果文件夹已经打开,那么就把它放在前面? 是否可以突出显示我的文件存在? 我正在使用 .NET 2 谢谢
迭代打开资源管理器windows是可以的,你必须使用ShellWindows object。开始项目 > 添加引用 > 浏览 > select c:\windows\system32\shdocvw.dll
这样使用:
Public Shared Sub OpenExplorerWindow(ByVal fileNameAndPath As String)
Dim folder = System.IO.Path.GetDirectoryName(fileNameAndPath)
Dim target As New Uri("file://" + folder)
Dim windows As New SHDocVw.ShellWindows
For Each win As SHDocVw.InternetExplorer In windows
Dim loc As New Uri(win.LocationURL)
If loc.Equals(target) Then
SetForegroundWindow(New IntPtr(win.HWND))
Exit Sub
End If
Next
Process.Start("explorer.exe", folder)
End Sub
Private Declare Function SetForegroundWindow Lib "user32.dll" (hWnd As IntPtr) As Boolean