5

If the dialog click Make new folder, just start editing the name just create a folder and click OK, OK dialogrezalt returns, but in the property SelectedPath he will name the folder New folder, then there is the name of the default

This happens because when we create, just edit and click OK, this property is not updated and the method ShowDialog () returns.

How fix this problem?

Thank you!

Invoker
  • 87
  • 1
  • 3
  • which framework version? – Renatas M. Jul 11 '11 at 08:56
  • It would be nice if you could make use of the formatting functions displayed at the top of the editor window you just had open. For example, you could use `useThisToTellCode` or `nameOfProperties`. Personally, I have a hard time understanding you post, but it would be easier if at least the formatting was properer. – Sebastian Mach Jul 11 '11 at 08:57
  • 1
    FW version - 4.0 I'm using a FolderBrowserDialog in my application. If I try to create a 'New Folder' within the FolderBrowserDialog and immediately after I try to rename the 'New Folder' and hit OK (not Enter) the SelectedPath property has the 'New Folder' in it's path and not the name that I entered on rename. – Invoker Jul 11 '11 at 09:09
  • 1
    I've seen the same issue. Its intermittent. Has anyone found a solution? – Sugrue Sep 19 '12 at 11:17
  • 1
    I had the same issue and indeed it is not consistently reproducible. – Dimitri C. Oct 28 '13 at 10:39
  • Same issue sometimes occurs on my applications too. Annoying. – Tolga Evcimen Jul 24 '14 at 11:18
  • Does this answer your question? [FolderBrowserDialog shows incorrect SelectedPath after new folder is being created and renamed](https://stackoverflow.com/questions/36541808/folderbrowserdialog-shows-incorrect-selectedpath-after-new-folder-is-being-creat) – Gerd K Mar 31 '22 at 07:56

2 Answers2

2

I had the same problem - if you created a new Folder with the FolderBrowseDialog, the .SelectedPath showed "xxx\NewFolder" not whatever new name the user had given.

The problem went away once I explicitly gave the command, prior to displaying the dialog,

MyFolderBrowser.ShowNewFolderButton = True

  • By looking at the implementation of `FolderBrowserDialog `I don't see why this would make a difference. The constructor already calls `Reset()` wich sets the value to true in the last statement. However [Microsoft recommends to avoid this dialog](https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shbrowseforfoldera). The .net documentation does not mention this. – Gerd K Mar 31 '22 at 07:37
0

I failed to simulate the problem you are describing, I have tested it:

Create a new Form Form1 add button1 to it and in the button1.Click handler copy this code:

private void button1_Click(object sender, EventArgs e)
{
    using (FolderBrowserDialog dialog = new FolderBrowserDialog())
    {
        dialog.ShowNewFolderButton = true;

        if (dialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
        {
            string path = dialog.SelectedPath;

            Console.WriteLine(path);//will not print new folder if the file renamed.
        }
    }
}

It worked as expected either by creating a new folder and press enter two times. or by creating a new folder and click ok. Are you using a third party UI Controls, theams...

Edit: You stated:

Yes, if this sample run at windows application, it work correct. But my application is Excel add-in. And FolderBrowserDialog work that I write at started post

So you are using a third party "Excel add-in", When using a third party with FolderBrowserDialog or OpenFileDialog.. you may notice a strange behavior depending on the third party..

The solution for the problem you described is either by disabling ShowNewFolderButton or implement your own custom OpenFileDialog.

Jalal Said
  • 15,906
  • 7
  • 45
  • 68
  • Yes, if this sample run at windows application, it work correct. But my application is Excel add-in. And FolderBrowserDialog work that I write at started post. – Invoker Jul 11 '11 at 10:29
  • I see, It turned out that the problem a little bit complicated then. You may notice a strange behavior when using a third party "Excel add-in in your case". The solution I can think of is either disabling the `ShowNewFolderButton` or building a custom open file dialog... – Jalal Said Jul 11 '11 at 10:45