VSTO:缓存交换模式VS LastModificationTime

时间:2010-02-18 14:30:34

标签: .net outlook vsto exchange-server outlook-addin

我正在开发一个依赖于Outlook Appointment的LastModificationTime属性的VSTO Outlook加载项。问题是当打开缓存交换模式时,每次关闭Outlook时LastModificationTime属性都会自动更新。是否有可能的解决方案,我可以用来获取用户更改约会的日期和时间,而不是缓存交换模式更改约会时的日期和时间?

看到没有很多回复我想更详细地描述我的问题 - 这就是发生的事情:

  1. 我更改了一个项目(异常行为仅发生在我已更改的项目上)
  2. LastModificationTime更改为我保存项目的时间(我看到OutlookSpy的更改)。 (例如,LastModificationTime 3:30:00 PM)
  3. 我工作到下午4:00:00,检查LastModificationTime,它仍然显示在下午3:30:00
  4. 我关闭了展望
  5. 我打开outlook并查看LastModificationTime。现在LastModificationTime显示3:30:42而不是3:30:00。 为什么在重新打开Outlook后又增加了42秒?
  6. 感谢您提供给我的任何建议。

1 个答案:

答案 0 :(得分:1)

我能找到两个解决我问题的方法,#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

谢谢所有帮助过的人