繁体   English   中英

从Outlook拖放到Winform

[英]Drag and drop from outlook to winform

我想添加一些功能,使用户无需使用Microsoft.Office.Interop.Outlook参考就可以将项目从Outllok拖放到Windows窗体应用程序中,因此我可以支持所有版本的Outlook。 我需要检测该项目是否是:电子邮件,会议或任务,并且还需要能够从该项目中提取所有字段。 我在CodeProject.com中找到了两个示例代码:

但是在这两种方法中,我都无法分辨所拖动的项目是什么,也无法获取日期和时间字段。 有谁知道怎么做?

引用Microsoft.Office.Interop.Outlook.dll ,这是一种非常简单明了的方法,没有第三方代码,可以从Outlook信息中获取删除的项目:

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

您仍然可以使用OOM-只要确保您使用的是您决定支持的最低版本的Outlook中的互操作即可。 或者,您可以使用后期绑定并通过反射进行所有操作。

您还可以使用Redemption及其RDOSession.GetMessageFromMsgFile方法-它在所有版本的Outlook(直到2013年一直使用97)中都可以使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM