I have found multiple questions about this article, such as this, this, this,
and this, in which the basic answers are that the FolderBrowserDialog
is not designed to select multiple folders.
Provided workarounds are to work with TreeViews, in which multiple files in multiple directories can be selected. This does not have my preference, since I do not want to select the individual files, but the folders they are located in.
However, the questions are all more that 10 years old, and don't really provide an answer. I was wondering whether it is possible by now to select multiple folders with the FolderBrowserDialog
, or something similar.
The following code is able to select only one folder:
namespace FolderSelector
{
using System.Collections.Generic;
using System.Windows.Forms;
/// <summary>
/// Select folders with browserdialog.
/// </summary>
public class FolderSelector
{
/// <summary>
/// Select folders with browserdialog.
/// </summary>
/// <returns>Folders.</returns>
public IList<string> SelectFolders()
{
// TODO: select multiple folders at once.
var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
return new List<string>(new string[] { fbd.SelectedPath });
}
return new List<string>();
}
}
}