我能够为我的问题找到两种解决方法,#1 对我来说是不可接受的,#2 我实际使用过:
解决方案 #1:使用注册表项在加载项关闭时禁用 Exchange 服务器,并在加载项启动时重新启用它。下面是示例代码:
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
Try
Dim regTopKey As String = "HKEY_CURRENT_USER"
Dim regPath As String = "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
Dim oldValue As Byte() = Registry.GetValue(regTopKey & regPath, "00036601_Backup", Nothing)
If oldValue IsNot Nothing Then
Registry.SetValue(regTopKey & regPath, "00036601", oldValue, RegistryValueKind.Binary)
End If
Catch
End Try
End Sub
Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
Try
Dim disableExchangeMode As Byte() = {4, 0, 0, 0}
Dim regTopKey As String = "HKEY_CURRENT_USER"
Dim regPath As String = "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
Dim currentValue As Byte() = Registry.GetValue(regTopKey & regPath, "00036601", Nothing)
If currentValue IsNot Nothing Then
Registry.SetValue(regTopKey & regPath, "00036601_Backup", currentValue, RegistryValueKind.Binary)
End If
Registry.SetValue(regTopKey & regPath, "00036601", disableExchangeMode, RegistryValueKind.Binary)
Catch
End Try
End Sub
解决方案#2:检测用户何时更改约会项目并将更改保存在用户定义的属性字段中。下面是示例代码:
Private Sub appointmentSave(ByVal Item As Object) Handles _m_olAppointment.ItemChange, _m_olAppointment.ItemAdd
Try
Dim dateNow As Date = Date.Now
If TypeOf Item Is Outlook.AppointmentItem Then
If (dateNow - _lastFolderSwitch).TotalMilliseconds > 500 Then
_lastFolderSwitch = dateNow
Dim appointmentItem As Outlook.AppointmentItem = CType(Item, Outlook.AppointmentItem)
If (dateNow - appointmentItem.LastModificationTime).TotalMilliseconds < 100 Then
Dim lastModifiedDate As Outlook.UserProperty = appointmentItem.UserProperties.Add("lastModifiedDate", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, True)
lastModifiedDate.Value = dateNow.ToString
appointmentItem.Save()
End If
End If
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
谢谢所有帮助过的人