Invoker
Invoker

Reputation: 97

Problem with FolderBrowserDialog

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!

Upvotes: 6

Views: 3475

Answers (2)

Peter Cunningham
Peter Cunningham

Reputation: 41

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

Upvotes: 2

Jalal Said
Jalal Said

Reputation: 16162

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.

Upvotes: 0

Related Questions