1

I open the FolderBrowserDialog via a ajax call to seelct a path on the machine. The dialog opens and works perfect at the first time but when I make the same call again the dialog does not open unless I rebuild the application.

I used OpenFileDialog as an alternative and it works fine but FolderBrowserDialog is what I need. What am I missing in my Code?

public string SelectFolder()
{
    string folderPath = null;
    var showDialog = new DialogResult();

    FolderBrowserDialog folderBrowser = new FolderBrowserDialog();
    Thread STAThread = new Thread(
        delegate ()
        {
            showDialog = folderBrowser.ShowDialog();
        });

    STAThread.SetApartmentState(ApartmentState.STA);
    STAThread.Start();
    STAThread.Join();

    if (showDialog == DialogResult.OK)
    {
        folderPath = Path.GetDirectoryName(folderBrowser.SelectedPath);
    }

    return folderPath;
}
user34534
  • 21
  • 5

0 Answers0