How do I open a FolderBrowserDialog at the selected folder?

后端 未结 9 1902
深忆病人
深忆病人 2020-12-15 18:00

I have a FolderBrowserDialog, displayed with code shown below. However, it keeps opening with \'Computer\', i.e. the root of the folder tree, selected. How do I get it to

9条回答
  •  死守一世寂寞
    2020-12-15 18:19

    This works for me:

    FolderBrowserDialog diag = new FolderBrowserDialog();
    diag.Description = "Select a folder in which to save your workspace...";
    diag.SelectedPath = Application.StartupPath;
    
    if (DialogResult.OK == diag.ShowDialog())
    {
        // do something here...
    }
    

    Set the SelectedPath property, not RootFolder.

    EDIT: Here's a screenshot showing the Application.StartupPath being in "C:\LocalDocuments\Visual Studio 2010\Projects\FolderBrowserDialogTest\FolderBrowserDialogTest\bin\Debug", which is most definitely not in the Desktop directory.

    enter image description here

提交回复
热议问题