Drag and Drop from Outlook using webbrowser control drop target

Jeff Kandt
CODE AUTHOR
Posts: 1
 1 month 1 week ago #550 by Jeff Kandt
Jeff Kandt created the code: Drag and Drop from Outlook using webbrowser control drop target
We've been struggling, like a lot of people apparently, with providing the ability to drag messages and attachments from Outlook into our PowerBuilder app.

We had been using Dddll.dll from Catsoft, but that stopped working when Outlook went to 64-bit, since we haven't yet migrated our app to 64-bit.

We looked at the clever method of using OLE described here: (community.appeon.com/index.php/qna/q-a/d...-from-64-bit-outlook) but found it has a number of functional disadvantages. Specifically, Dddll.dll is still used to notify PB when something got dropped from Outlook, but it doesn't communicate exactly what was dropped. So it then makes an OLE connection to Outlook and calls methods to determine what is currently selected within Outlook and then tells Outlook to export the selected message(s).

The problem with this is that what's selected isn't always what was dragged. In the example code, when the user drags attachments out of a message, the entire message gets exported instead. And if the user selected a different message in their Inbox before dragging out of the message window, the selected message was attached instead of the one being dragged out of. In trying to fix these issues we found that there are some situations in which it appears to be impossible via OLE to determine what was actually dragged out of Outlook. As one worst-case example: When the user is dragging out of a preview pane in their Inbox, the user may have multiple types of entities selected at once: attachments selected in the preview pane, plus messages selected in the list. Did the user drag the message(s) or attachment(s)?

In the end, we found what I believe to be a better solution that I wanted to share here: A webbrowser object used as a drag target. The page loaded in the webbrowser contains Javascript to access the HTML5 Drag-and-Drop and File APIs, and passes the name and binary data from the dropped files into PowerBuilder by calling a PB event. In order to be called from Javascript, the PB event can only accept a single string argument, so the file data is encoded to base 64.

One thing I ran into was an apparent limit on the size of the string that can be passed into the PB event. To get around that, the javascript "chunks" the file data into 32k pieces and calls the event for each chunk. The PB event then has to re-assemble the chunks.

The new webbrowser control's Chromium-based engine has excellent support for drag-and-drop, with no apparent 32/64 bit issues. It is able to pull messages and attachments out of Outlook, as well as files from File Explorer. As a special bonus in our environment where some users run our app via Citrix, it even supports dragging across the local/remote boundary: You can drag messages and attachments out of a locally running instance of Outlook and into our remotely hosted PB app.

As noted in the post on the OLE method, the "New Outlook" doesn't support drag and drop yet, so until Microsoft fixes this we'll be encouraging our users to switch back to the "old" Outlook if they want any of this to work.

The main disadvantage of this method is that it doesn't enable dropping directly into an existing PB control, such as a datawindow, like we could before. Instead. the browser control must be a separate visible "Drop files here" area on the window, specifically used only as a drag target. I tried various ways to make the browser control transparent and position it over the PB control so that it looks like you can drop onto an existing control, but couldn't make it work -- please let me know if anyone figures that out.

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

David Peace (Powersoft)
 1 day 13 hours ago #571 by David Peace (Powersoft)
David Peace (Powersoft) replied the code: Drag and Drop from Outlook using webbrowser control drop target
Code updated to extract more details from the Email Headers, now gets All To, CC addresses, Date etc.

There is still a small issue with complex email headers, once I debug and fix that I'll submit an update. JavaScript is not me strong point. Any help welcome.

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.

David Peace (Powersoft)
 1 month 5 days ago #551 by David Peace (Powersoft)
David Peace (Powersoft) replied the code: Drag and Drop from Outlook using webbrowser control drop target
Thanks, we have grabbed this great piece of code and updated it to parse MSG type file and grab the Email Sender info etc. I'm sure this can be extended further.

We also changed it to be a userobject that can be dropped on any window.

Attached is our updated code, fell free to develop it further

Cheers

David Peace (Powersoft)

This message has an attachment file.
Please log in or register to see it.

Please Log in or Create an account to join the conversation.