locked
How to open a folder in "My Documents" using this code via vb.net? RRS feed

  • Question

  • Hi,

    I am trying to make a button that opens a folder in "My Documents" using the following code but it doesn't work.

    Dim path = (My.Computer.FileSystem.SpecialDirectories.MyDocuments) \ "RM Screenshot Pro"
    Process.Start("path")

    Any help please?

    Thanks advance

    Monday, January 27, 2020 12:02 AM

Answers

  • Dim sPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments + "\RM Screenshot Pro"
    Process.Start(sPath)

    • Proposed as answer by simonb549 Monday, January 27, 2020 7:59 AM
    • Marked as answer by Max45-1 Monday, January 27, 2020 10:18 AM
    Monday, January 27, 2020 12:35 AM

All replies

  • Dim sPath As String = My.Computer.FileSystem.SpecialDirectories.MyDocuments + "\RM Screenshot Pro"
    Process.Start(sPath)

    • Proposed as answer by simonb549 Monday, January 27, 2020 7:59 AM
    • Marked as answer by Max45-1 Monday, January 27, 2020 10:18 AM
    Monday, January 27, 2020 12:35 AM
  • Hi

    Try this. You can rely on the Path.Combine to form a good string.

    ' create the path using SpecialDirectory and a sub folder name (Gallery) Dim path As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Gallery") ' open file explorer at the path Process.Start(path)

    Dim path As String = IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, "Gallery", "Freddy", "MyGoodnessGraciousMe")
    
    for example, path =  " C:\Users\lesha\Documents\Gallery\Freddy\MyGoodnessGraciousMe"


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, January 27, 2020 12:39 AM
    • Proposed as answer by KareninstructorMVP Monday, January 27, 2020 1:51 AM
    Monday, January 27, 2020 12:36 AM
  • Use what Les has shown


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Monday, January 27, 2020 1:49 AM