OpenFileDialog on .NET Core

2020-02-15 01:14发布

问题:

On .NET Framework you can use System.Windows.Forms.OpenFileDialog for open files with the native Windows UI but that only works on Windows.

There is a System.Windows.Forms.OpenFileDialog implementation for .Net Core or another alternative?

回答1:

.NET Core itself does not include APIs for any UI. For example, https://docs.microsoft.com/en-us/dotnet/api/?view=netcore-2.0&term=File shows nothing relevant. This is also the current stance of .NET Core developers: https://github.com/dotnet/core/issues/374

There are several external libraries that may work on specific platforms:

  • https://github.com/AvaloniaUI/Avalonia
  • http://www.mono-project.com/docs/gui/gtksharp/

If you are not really tied to .NET Core itself. UWP (which builds on top of .NET Standard but is different from .NET Core) may be an option too.



回答2:

Since .NET Core added support for Windows desktop applications, WPF and Windows Forms applications that target .NET Core can use the OpenFileDialog and SaveFileDialog APIs exactly the same way as they would do in the .NET Framework.

These APIs have been ported to the Windows specific desktop packs that sit on top of .NET Core 3 and later.