I want to be able to drag & drop an email message from Outlook onto my form & then save the message to a specified location & also save any attachments to a specified location. I created a label that will accept drag/drop & have the required event handlers in my code. The problem now is I don't know how to cast the dropped message to an Outlook.MailItem object.
When I drop a message onto the label I get this error:
"Unable to cast object of type 'System.Windows.Forms.DataObject' to type 'Microsoft.Office.Interop.Outlook._MailItem'"
Is there a way to convert the DataObject directly to an MailItem object. Thanks for any help...
This is the code I am trying.
Code:Imports Microsoft.Office.Interop Private Sub Label1_DragEnter(sender As Object, e As DragEventArgs) Handles Label1.DragEnter Dim dataFormat = e.Data.GetFormats(False)(1) If dataFormat = "RenPrivateLatestMessages" Then e.Effect = DragDropEffects.Copy End If End Sub Private Sub Label1_DragDrop(sender As Object, e As DragEventArgs) Handles Label1.DragDrop Try If e.Data.GetFormats(False)(1) = "RenPrivateLatestMessages" Then Dim oApp As Outlook._Application Dim oMsg As Outlook._MailItem oApp = New Outlook.Application oMsg = CType(e.Data, Outlook._MailItem) <-- stops here End If Catch ex As Exception 'handle error End Try End Sub




Reply With Quote