I am working on a WPF application under .NET Core 3.1 which should support drag & drop of one or multiple files. When dropping the file(s), I use IDataObject
to retrieve the list of dropped files as follows
string[] files = dataObject.GetData(DataFormats.FileDrop) as string[] ?? new string[] { };
which is working fine if the file paths do not exceed a certain limit.
However, I run into problems when dropping files with long file paths. I get the following the exception:
The data area passed to a system call is too small. (0x8007007A)
For further info, the stack trace reads as follows:
at System.Runtime.InteropServices.ComTypes.IDataObject.GetData(FORMATETC& format, STGMEDIUM& medium)
at System.Windows.DataObject.OleConverter.GetDataFromOleHGLOBAL(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetDataFromBoundOleDataObject(String format, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert, DVASPECT aspect, Int32 index)
at System.Windows.DataObject.OleConverter.GetData(String format, Boolean autoConvert)
at System.Windows.DataObject.GetData(String format, Boolean autoConvert)
at MyApplication.Commands.DropFileCommand.GetFile(IDataObject dataObject) in D:\\MyApplication\\Commands\\DropFileCommand.cs:line 272
dataObject.GetDataPresent(DataFormats.FileDrop)
returns true
and dataObject.GetFormats()
lists DataFormats.FileDrop
as an available format. Passing true
or false
as autoConvert
parameter to IDataObject.GetData
does not change anything.
Is there any possibility to retrieve the dropped file?
A similar question has already been asked in a WinForms context, see here: https://stackoverflow.com/questions/44253187; however, the question has not really been answered and was already asked three years ago.
Any help is greatly appreciated.
User contributions licensed under CC BY-SA 3.0