2016-03-04 69 views
0

我有下面的代碼處理我從一個電子郵件從拖放到表單文本框。我遇到的問題是代碼工作後拖放Outlook的實例視覺凍結。我認爲我需要以某種方式釋放前景,但我不知道如何。Outlook拖放.msg錯誤

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 

回答

0

儘量不要在拖放處理程序中使用Outlook對象模型。請注意,FileGroupDescriptor將包含MSG格式的消息。

+0

不知道如何使用FileGroupDescriptor獲取.msg文件 – Lickrob

+0

請參閱http://stackoverflow.com/questions/8709076/drag-and-drop-multiple-attached-file-from-outlook -to-C-尖銳窗口狀 –