Initial path in FolderBrowserDialog

Answered Initial path in FolderBrowserDialog

  • Thursday, August 16, 2012 7:24 AM
     
     

    Hi,

    I'm trying to set the initial path in a FolderBrowserDialog by something like this:

                FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

                folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
                folderBrowserDialog.SelectedPath = @"C:\MyPath\...\";

                if (folderBrowserDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                catalogPath = folderBrowserDialog.SelectedPath;

    When the FolderBrowserDialog is shown, the folder tree is not expanded to the specified SelectedPath (as it should according to the MicroSoft Help pages). It seem to me that this is a bug appearing in Windows 7. Does anyone know a workaround for this?

    Kind regard

    Edvard

All Replies

  • Thursday, August 16, 2012 11:21 AM
     
     

    Hi,

    when I look at the documentation of SelectedPath, I find:
    "If the SelectedPath property is set before showing the dialog box, the folder with this path will be the selected folder, as long as SelectedPath is set to an absolute path that is a subfolder of RootFolder (or more accurately, points to a subfolder of the shell namespace represented by RootFolder)."

    If I look at your example, The Desktop should be something like c:\users\<userid>\desktop and c:\mypath is not a subfolder of it.

    Could that be the problem you encountered?

    With kind regards,

    Konrad

  • Friday, August 17, 2012 9:37 AM
     
     Answered

    Thank you very much for the answer. I have finally figured out what was wrong: the path contained swedish characters. Paths without swedish characters works fine. If anyone knows how to include paths with non-english characters I would be very grateful.

    Thanks

    Edvard

  • Friday, August 17, 2012 9:53 AM
    Moderator
     
      Has Code

    Hi kalleball,

    Unfortunately I cannot reproduce your issue. I have tried to set the SelectedPath:

    folderBrowserDialog.RootFolder = Environment.SpecialFolder.Desktop;
    folderBrowserDialog.SelectedPath = @"C:\Program Files\";

    And it works well on my machine (Windows 7 Enterprise).

    Have you checked if your path is right and you have permission to it?

    What is "..." in your path, just part of you full path you have omitted?

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • Friday, August 17, 2012 11:26 AM
     
     

    Ok,

    This code works fine for me:

          folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;

          folderBrowserDialog.SelectedPath = @"C:\Temp\SLE-LIU1";

    This code don't work
          folderBrowserDialog.RootFolder = Environment.SpecialFolder.MyComputer;

          folderBrowserDialog.SelectedPath = @"C:\Småjobb\Jan11\Kundrapporter";

    I think it's the swedish character 'å' in Småjobb that's the problem.

    Edvard

  • Monday, August 20, 2012 10:40 AM
    Moderator
     
     

    Hi Edvard,

    Thanks for sharing your progress.

    But I tried to create a folder like yours, it works for me either.

    I'm not sure whether there is an encoding issue.

    http://msdn.microsoft.com/en-us/library/w11571b4(v=vs.100).aspx

    Best regards,


    Chester Hong
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.