简体   繁体   中英

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.

Process.Start(“目录路径”)

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)

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 properrlly:

    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)

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 .

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

.txt可能是你需要的。

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 mistype the "folder_path" and the specified folder doen not exists

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM