Choosing a non-standard FolderBrowserDialog.RootFolder Property, or the functional root-folder equivalent

Ron Sipherd 241 Reputation points
2022-11-28T04:07:16.86+00:00

So far as I can tell, the
FolderBrowserDialog.RootFolder Property
can only be one of the
Environment.SpecialFolder Enum values.

I would like to open a folder browser dialog rooted at a data directory of my choice.
Am looking at how to do this, and not finding a good (simple) solution.
Is there one?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,661 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 28,946 Reputation points Microsoft Vendor
    2022-11-28T06:41:01.887+00:00

    Hi @Ron Sipherd ,
    You can try to use FolderBrowserDialog.SelectedPath Property to set the initial directory displayed by the folder browser dialog.
    FolderBrowserDialog1.SelectedPath = "C:\Users\Administrator\Desktop" before showdialog.
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. RLWA32 43,046 Reputation points
    2022-11-28T12:29:15.27+00:00

    You can drop down to the Windows API functions using p/invoke to achieve your objective. Following is a quick example in .Net Framework 4.8 using a Windows Forms project (Error handling omitted). Sorry about posting an image, the site wouldn't accept posted code.

    264812-folderbrowser.png

    And the execution -

    264790-dlgrunning.png

    264823-ok1.png

    264841-ok2.png

    0 comments No comments

  2. Ron Sipherd 241 Reputation points
    2022-11-28T20:35:54.687+00:00

    Thanks to both of you! I'll take a closer look and respond.

    0 comments No comments

  3. Ron Sipherd 241 Reputation points
    2022-11-28T21:44:48.233+00:00

    SelectedPath is not the same as a root folder, but it's good enough for this task.
    I'll dive into PInvoke when I run into a problem that requires it.

    Signed,
    Did lots of DLL calls back when I was young and foolish