1
votes

I want to add functionality that enables users to drag and drop item from outllok to a windows form application, WITHOUT USING Microsoft.Office.Interop.Outlook reference so I could support all versions of outlook. I need to detect whether the item is: email, meeting or task and I also need to be able extract all fields from the item. I found two sample codes in CodeProject.com:

But in both of them I can't tell what the dragged item is, and I also can't retrieve the date and time fields. Does anyone know how is it possible to be done ?

1

1 Answers

1
votes

Referencing Microsoft.Office.Interop.Outlook.dll, this is a very simple and straightforward method, no third party code, to get a dropped item from Outlook info:

Imports Microsoft.Office.Interop

.....

Private Sub MainForm_DragEnter(sender As Object, e As DragEventArgs) Handles Me.DragEnter, TextBox1.DragEnter
    DragStart = True
End Sub

Private Sub MainForm_DragOver(sender As Object, e As DragEventArgs) Handles Me.DragOver, TextBox1.DragOver
    If DragStart Then
        If e.Data.GetFormats.Contains("Csv") OrElse e.Data.GetFormats.Contains("CSV") Then
            e.Effect = DragDropEffects.Copy
        End If
    End If
    DragStart = False
End Sub

Private Sub GetFromOutlook()
    Dim myOlApp As New Outlook.Application
    Dim myExp As Outlook.Explorer = myOlApp.ActiveExplorer
    Dim myMailItem As Outlook.MailItem = DirectCast(myExp.Selection.Item(1), Outlook.MailItem)

    ' (with debug) you can check other properties
    'For Each ipp As Outlook.ItemProperty In myMailItem.ItemProperties
    '    Dim x1 = ipp.Name
    '    Dim x2 = ipp.Value
    'Next

    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001F"
    Const PR_MAIL_HEADER_TAG = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"
    Dim oPA As Outlook.PropertyAccessor = myMailItem.PropertyAccessor 'As Outlook.PropertyAccessor
    Dim Header As String = oPA.GetProperty(PR_MAIL_HEADER_TAG)
    Dim messageBody = myMailItem.Body
    myExp = Nothing
    myMailItem = Nothing
    myOlApp = Nothing

   '
   ' ......enter your code here
   '

End Sub