It’s great that, even after so many years, the teams at Microsoft continue to add updates to their oldest technologies with every .NET release. WinForms recently got a particularly small one, in .NET 9, that allows the FolderBrowserDialog to select multiple directories instead of one, so let’s check it out (it won’t take long, lol).
The code in this post is available on GitHub, for you to use, extend, or just follow along while you read… and hopefully discover something new along the way!
The old FolderBrowserDialog (one at a time, please)
The FolderBrowserDialog control has always given us an easy way to select a single folder in an app. After confirming the user pressed OK, we just read in the SelectedPath
property and move on with life:
|
|
There’s a lot of other available properties with this control too, but they didn’t change so I won’t bother with them. They’re there though. 😏
The new FolderBrowserDialog (the more, the merrier)
The only change we have to make with the updated control in .NET 9 is to set the Multiselect
property to true
, either in the designer or at runtime:
|
|
Then we call it the same way but reference the new SelectedPaths
property, which is an array of strings:
|
|
![](