0

I have the below code handling my Drag and Drop of an email from outlook into a forms textbox. The problem i am having is after the code works the drag and drop the instance of outlook visually freezes. i assume i need to release outlook in some way but i am not sure how.

Private Sub frm_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles tbAppEmail.DragDrop
    tbAppEmail.Text = String.Empty
    Try

        If e.Data.GetDataPresent(DataFormats.FileDrop) Then
            'supports a drop of a file from Windows Explorer

            'Removed for visibility 


        ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
            'supports a drop of a Outlook message

            'Dim objMI As Object - if you want to do late-binding
            Dim objMI As Microsoft.Office.Interop.Outlook.MailItem

            For Each objMI In objOL.ActiveExplorer.Selection()
                'hardcode a destination path for testing
                Dim strFile As String = _
                            IO.Path.Combine("\\ud1.utility\GSA\LWREPPLA\Databases_Dont_Touch\RTTEmails", _
                                            (objMI.Subject + ".msg").Replace(":", ""))
                tbAppEmail.Text += strFile + Environment.NewLine
                objMI.SaveAs(strFile)
            Next
        End If
        'tbAppEmail.Text = String.Empty

    Catch ex As Exception
        tbAppEmail.Text = "An error occured in the drop event" + Environment.NewLine + ex.ToString
    End Try
End Sub
Lickrob
  • 61
  • 2
  • 11

1 Answers1

0

Try not to use the Outlook Object Model from your drop handler. Note that the FileGroupDescriptor will contains the messages in the MSG format.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78