【发布时间】: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