我有代码可以拖放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发布于 2015-08-04 11:54:47
根据文档,Application.ActiveExplorer方法返回一个Explorer对象。Selection()对象的Explorer属性返回Collection对象。
Collection是一个可枚举的对象,因此它有一个名为.Count的属性,它将告诉您它包含多少项。可以使用此属性检查所选内容是否包含多个项目,如下所示:
if objoL.ActiveExplorer.Selection.Count >1 thenhttps://stackoverflow.com/questions/31797997
复制相似问题