0

I'm using the Ookii Vista folder dialog for ease of use, and I have this code going on which is called from a button:

using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Ookii.Dialogs;

private string LoadDirectories()
{
    VistaFolderBrowserDialog fbd = new VistaFolderBrowserDialog();
    if (fbd.ShowDialog() == DialogResult.OK && fbd.SelectedPath.Contains("U000"))
    {
        return fbd.SelectedPath;
    }
    else
    {
        MessageBox.Show("Folder must be root assembly, which has U000 in name");
    }
    
    return string.Empty;
}

Currently, if the user does not pick a folder with U000 in the name, the dialog will close, but I want it to stay open until user either cancels or sets the correct folder path. I can't find this anywhere.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Jaymar
  • 27
  • 7

1 Answers1

1

A simple realization of your needs (Add a while):

Used nuget: Ookii.Dialogs.Wpf

private string LoadDirectories()
{
    VistaFolderBrowserDialog fbd = new VistaFolderBrowserDialog();
    while (true)
    {
        if (fbd.ShowDialog() == false)
        {
            break;
        }
        else if (fbd.SelectedPath.Contains("U000"))
        {

            return fbd.SelectedPath;
        }
        else
        {
            MessageBox.Show("Folder must be root assembly, which has U000 in name");
        }
    }
    return string.Empty;
}

output:

enter image description here

Jiale Xue - MSFT
  • 3,560
  • 1
  • 6
  • 21