Marko Stojkovic
Marko Stojkovic

Reputation: 3375

VB.NET, open specific folder in windows explorer?

I have problem with opening specific folder in VB.net in Windows Explorer. I used

Process.Start("explorer.exe", "Folder_Path")

Always when i tried this it open documents in explorer , whatever i wrote. Pls help.

Upvotes: 27

Views: 109969

Answers (7)

ElektroStudios
ElektroStudios

Reputation: 20464

The reason why it opens the default directory (MyDocuments) only could be one of these two reasons:

  • The directory does not exist.

  • The directory path contains spaces in the name, and arguments containing spaces should be enclosed with doublequotes, this is a BASIC rule of programming.

Then use the syntax properly:

    Dim Proc As String = "Explorer.exe"

    Dim Args As String =
       ControlChars.Quote &
       IO.Path.Combine("C:\", "Folder with spaces in the name") &
       ControlChars.Quote

    Process.Start(Proc, Args)

Upvotes: 5

Marko Stojkovic
Marko Stojkovic

Reputation: 3375

Process.Start("directory path")

Upvotes: 55

Process.Start("explorer.exe", "/select," + "C:\File_Name.txt")

The .txt could be what ever u need.

Upvotes: 3

Ruby Kousinovali
Ruby Kousinovali

Reputation: 347

You can try Process.Start("explorer.exe", "Folder_Path") like you said.

The only reason that Windows Explorer opens the Documents folder is that you mistyped the "folder_path" and the specified folder does not exist.

Upvotes: 2

Steve Hargrave
Steve Hargrave

Reputation: 11

I know this is an old question but there is no reason to get overly complicated; so, just use like this:

Process.Start("explorer.exe", Chr(34) & "folder to open" & Chr(34))

Upvotes: 1

keenthinker
keenthinker

Reputation: 7820

You could start explorer with preselected directory like this:

Process.Start("explorer.exe", String.Format("/n, /e, {0}", "d:\yourdirectory\"))

The Windows Explorer options are explained in this Microsoft KB article.

Upvotes: 9

Vince
Vince

Reputation: 3577

Try opening it with:

Process.Start("explorer.exe", "/root,Folder_Path")

Or change the path before:

SetCurrentDirectory("Folder_Path")
Process.Start("explorer.exe")

And if it still fails, go with the shell command:

Shell("explorer Folder_Path", AppWinStyle.NormalFocus)

Upvotes: 10

Related Questions