Mik*_*ole 4 vb.net drag-and-drop outlook-addin outlook-2010
我有一个可以放邮件项目的控件,工作正常,但无法清除选择/项目。
例如:我将邮件1拖放->邮件1在我的列表中从列表中删除邮件1返回Outlook并拖放邮件2
邮件2出现在我的列表中,但邮件1也已恢复!我发现了很多相关的帖子,Marshal.ReleaseComObject但我想我做得不好?
规格:VS2010、4.0框架。Windows 7操作系统,Outlook 2010
这是我的代码的一部分:
调用我的Save方法:
ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then
Try
Dim SafeSaveMethod As New dlgCallSaveMails(AddressOf SaveMailsFromSelection)
Me.BeginInvoke(SafeSaveMethod, Me.FileData.Pad)
Run Code Online (Sandbox Code Playgroud)
该Save方法:
Private Sub SaveMailsFromSelection(_path As String)
' File uit Outlook
Dim x As Integer
Dim xitmndx As Integer = 0
Dim DestFile As String
Dim oOutLook As New Outlook.Application
Dim oExplorer As Outlook.Explorer
Dim oSelection As Outlook.Selection
Dim strFile As String
oExplorer = oOutLook.ActiveExplorer
oSelection = oExplorer.Selection
Dim currentFolder As MAPIFolder = oExplorer.CurrentFolder
Dim folders As Folders = currentFolder.Folders
Try
For Each mitem As Object In oSelection
xitmndx += 1
Dim mi As Microsoft.Office.Interop.Outlook.MailItem = TryCast(mitem, Microsoft.Office.Interop.Outlook.MailItem)
mi.SaveAs(_path & "\" & String.Format("{0:yyyy-MM-dd_hh-mm-ss-tt}", mi.CreationTime) & "-" & CleanInput(mi.Subject) & ".msg", Outlook.OlSaveAsType.olMSG)
Marshal.ReleaseComObject(mi)
mi = Nothing
Next
Catch ex As System.Exception
WriteError2EventLog("Error picDropZone_DragDrop 4: " & ex.ToString)
MsgBox(Err.Description, MsgBoxStyle.Exclamation, "mycontrol")
Finally
Marshal.ReleaseComObject(oExplorer)
Marshal.ReleaseComObject(oSelection)
Marshal.ReleaseComObject(currentFolder)
Marshal.ReleaseComObject(folders)
Marshal.FinalReleaseComObject(oExplorer)
End Try
End Sub
Run Code Online (Sandbox Code Playgroud)
我也尝试过,oExplorer.ClearSelection()但从count属性可以看出,它根本无法清除
小智 6
花了数小时阅读了针对该问题的不同解决方案后,发现当移到可以处理另一个程序中拖放操作的控件时,它最终成为Outlook中处理回车事件的方式中的一个错误,我发现可以对其进行修复。只需一行代码,那是应该传播的东西!
Microsoft使用剪贴板来存储有关选择的信息。Outlook为此目的使用的类隐藏在名为RenPrivateMessages的键的后面。它不能使用,因为他们不会释放该接口,但是通过阅读它,您可以清除所选内容上的锁定。
因此,在代码的drop-event中要做的就是添加此行(假设您的EventArg名为e):
e.data.GetData(“ RenPrivateMessages”);
| 归档时间: |
|
| 查看次数: |
1618 次 |
| 最近记录: |