Yes it's possible, but the FolderBrowserDialog
is just a portion of the solution. It might look something like this:
using (var fbd = new FolderBrowserDialog())
{
if (fbd.ShowDialog() == DialogResult.OK)
{
foreach (var file in Directory.GetFiles(fbd.SelectedPath,
"*.png", SearchOption.AllDirectories)
{
// this catches things like *.png1 or *.pngp
// not that they'd ever exist; but they may
if (Path.GetExtension(file).Length > 4) { continue; }
var pictureBox = new PictureBox();
pictureBox.Load(file);
// set its location here
this.Controls.Add(pictureBox);
}
}
}
This code only searches for png
files, and it's worth noting that the reason I check the extension is because of the little known caveat on 3-character extension searches:
A searchPattern with a file extension of exactly three characters returns files having an extension of three or more characters, where the first three characters match the file extension specified in the searchPattern.