Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 5.0 Open Select Folder Dialog [duplicate]

Tags:

c#

.net

winforms

I am having trouble with a new .NET 5.0 application. I want to have a select folder dialog open, but I haven't found a class for that. All the code I find references the System.Windows.Forms library.

using (var dialog = new System.Windows.Forms.FolderBrowserDialog())
{
    System.Windows.Forms.DialogResult result = dialog.ShowDialog();
}

What is the new way?

like image 947
Alan Avatar asked Jan 26 '26 22:01

Alan


1 Answers

I didn't realize I needed to edit the .csproj file, nor did I know you could have both WPF and Windows Forms declared at the same time there. I kept thinking I needed to add it as a reference.

Modifying the project file in this way worked and allowed me to declare using System.Windows.Forms; without getting an error.

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <RootNamespace>WpfApp1_5</RootNamespace>
    <UseWPF>true</UseWPF>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
like image 163
Alan Avatar answered Jan 28 '26 15:01

Alan