Select a file in Explorer

  • Thread starter Thread starter Sergey Poberezovskiy
  • Start date Start date
S

Sergey Poberezovskiy

Hi,

As part of my Windows application, I need to open a folder
containing a file (fileName is specified in txtFile).
I have no problem opening the folder:
Dim directoryName As String = New FileInfo
(txtFile.Text).DirectoryName
Dim startInfo As System.Diagnostics.ProcessStartInfo =
New System.Diagnostics.ProcessStartInfo
With startInfo
.FileName = "explorer"
.UseShellExecute = True
.WindowStyle = ProcessWindowStyle.Normal
.Arguments = """"c & directoryName & """"c
End With
System.Diagnostics.Process.Start(startInfo)

But how do I select the file within the opened directory?

Any help is much appreciated.
 
Sergey,

Please do not multipost.
You can crosspost what is sending one messages to more relevant newsgroups

Cor
 
Sergey Poberezovskiy said:
As part of my Windows application, I need to open a folder
containing a file (fileName is specified in txtFile).
I have no problem opening the folder:
Dim directoryName As String = New FileInfo
(txtFile.Text).DirectoryName
Dim startInfo As System.Diagnostics.ProcessStartInfo =
New System.Diagnostics.ProcessStartInfo
With startInfo
.FileName = "explorer"
.UseShellExecute = True
.WindowStyle = ProcessWindowStyle.Normal
.Arguments = """"c & directoryName & """"c
End With
System.Diagnostics.Process.Start(startInfo)

But how do I select the file within the opened directory?

I doubt that there is a direct way to do that. What you can try to do is
using 'SendKeys' to send the filename to the window, but this would not be a
reliable solution.
 
Sergey Poberezovskiy said:
Hi,

As part of my Windows application, I need to open a folder
containing a file (fileName is specified in txtFile).
But how do I select the file within the opened directory?

Any help is much appreciated.

Try this:

Shell("explorer , """ & txtFile & """, /select", AppWinStyle.NormalFocus)

HTH
LFS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top