We want to be able to import multiple files from a smartphone connected to a computer via USB connection. However, it seems impossible to do so using the
OpenFileDialog, because it fires message box "Cannot open multiple items from this location. Try selecting a single item instead.". You can reproduce it using this simple code and selecting at least 2 pictures from your smartphone:
var openFileDialog = new Microsoft.Win32.OpenFileDialog(); openFileDialog.Multiselect = true; openFileDialog.ShowDialog();
This problem is known (see here and here) and related to the MTP protocol. The problem does not occur with a smartphone connected using the alternative "USB Mas Storage" (UMS), but this option is not available on modern smartphones.
The UWP `FileOpenPicker` seems to handle better the selection of multiple items (see here to see how to use it in a WPF app) but we accounter an
InvalidCastException when using
PickMultipleFilesAsync. The problem is described here and the answers suggest that
FileOpenPicker cannot be used in WPF .NET Framework apps.
An other way to achieve this would be to implement a file picker from skratch, using the MTP protocol for the smartphone devices.
The downside of this approach is that the .NET and UWP file pickers offer a lots of great features and are fully integrated to the OS.
We have run out of ideas to solve this problem, so my question is:
Is there a way to import multiple files from a smartphone using the Windows file picker in a WPF app targeting .NET Framework?