I have found this CodeProject article on how to get data when dragging attached files from Microsoft Outlook into a .net control.
When dragging other types of data into the control, however, the code throws an exception, so I only want to use this method in the specific case of dragging data from Outlook.
Unfortunately, I can’t see an obvious way to determine the origin of the DragDrop event and so can’t actually tell when a file has been dragged from Outlook.
Am I missing something obvious?
Not being able to discover exactly where the dragged data came from is very much a design feature of D+D. It helps to completely isolate the drag source from the process that receives the data. Very important in Windows, it makes dragging from, say, a 64-bit process into a 32-bit process simple. It completely avoids the many headaches of getting processes to interop correctly. Only the data matters.
You’ll need to screen the dragged data in the DragEnter event handler and ensure it is data that you know how to handle. The primary protocol for that is e.Data.GetDataPresent() which tells you that the data has the right format. Do not set e.Effect unless you are happy with what you see.
The DragDrop event handler should then accept the data. Getting an exception there is not entirely unexpected, particularly if you didn’t screen it well enough in DragEnter. This otherwise doesn’t cause your program to crash, the exception is swallowed and nothing happens. Debug your code with Debug + Exceptions, tick the Thrown checkbox for CLR exceptions.