【问题标题】:VB.net Drag SINGLE Outlook msg and drop on formVB.net 将单个 Outlook 消息拖放到表单上
【发布时间】:2015-08-04 21:22:09
【问题描述】:

我有代码可以将 Outlook 项目拖放到我的表单(标签)上,但我想确保只删除一个文件。那么如何正确编码以禁止来自 Outlook 的多个文件并提示用户只输入一个文件?

Private Sub Label1_DragDrop(sender As Object, e As DragEventArgs) Handles Label1.DragDrop
        lblFile.Text = String.Empty
        Try

            If 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("c:\temp", _
                                                (objMI.Subject + ".msg").Replace(":", ""))
                    lblFile.Text += strFile + Environment.NewLine
                    objMI.SaveAs(strFile)
                Next
            End If
            lblFormat.Text = String.Empty
            IO.File.Delete(lblFile.Text)
        Catch ex As Exception
            lblFile.Text = "An error occured in the drop event" + Environment.NewLine + ex.ToString
        End Try
    End Sub

【问题讨论】:

  • if objoL.ActiveExplorer.Selection.Count >1 then
  • 完美。不知道如何回答评论。
  • 无法回复评论,但我没有时间将其全部输入。我会添加一个答案...

标签: vb.net drag-and-drop outlook


【解决方案1】:

根据文档,Application.ActiveExplorer 方法返回一个 Explorer 对象。 Explorer 对象的Selection() 属性返回一个Collection 对象。

Collection 是一个可枚举对象,因此它有一个名为 .Count 的属性,它会告诉您它拥有多少个项目。您可以使用此属性来检查选择是否包含多个项目,如下所示:

if objoL.ActiveExplorer.Selection.Count >1 then

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 1970-01-01
    • 2023-04-06
    • 2015-05-29
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多