问题描述
我开发一个VSTO Outlook加载项是依靠Outlook约会的LastModificationTime财产。问题是,当缓存Exchange模式打开时,我每次关闭Outlook时LastModificationTime属性自动更新。有可能的解决方案,我可以使用,而不是日期和时间来获得日期和时间,如果用户更改了约会,当缓存Exchange模式改变了约会?
I am developing a VSTO Outlook Add-In that is relying on the LastModificationTime property of Outlook Appointment. The problem is when Cached exchange mode is turned On, the LastModificationTime property auto updates each time I close Outlook. Is there possible solution I can use to get the date and time when user changed the appointment, instead of date and time when cached exchange mode changed the appointment?
眼看有没有很多的反应,我想说明我的问题详细 - 这是发生了什么:
Seeing that there are not a lot of responses I wanted to describe my problem in more detail - this is what happens:
- 在我更改项目(异常行为只发生在项目我已经改变了)
- LastModificationTime被改变时,我已经保存的项目(我看到OutlookSpy的变化)的时间。 (如LastModificationTime下午3时30分00秒)
- 在我的工作,直到下午四点00分00秒,并检查LastModificationTime,它仍然显示了下午3时30分○○秒
- 在我关闭Outlook
- 在我打开Outlook,并检查LastModificationTime。现在LastModificationTime显示三时三十分42秒,而不是3时三十零分00秒。为什么会增加额外的42秒我已经重新开放了展望后?
- I change an item (the abnormal behavior happens only to items I've changed)
- LastModificationTime is changed to the time when I've saved the item (I see the change with OutlookSpy). (eg. LastModificationTime 3:30:00 PM)
- I work until 4:00:00 PM and check the LastModificationTime and it still shows 3:30:00 PM
- I close outlook
- I open outlook and check LastModificationTime. Now the LastModificationTime shows 3:30:42 instead of 3:30:00.Why did it add extra 42 seconds after I had reopened the Outlook?
感谢您对您能给我什么建议。
Thank you for any suggestions you can give me.
推荐答案
我能找到两种解决我的问题,#1所不能接受的,我和#2我实际使用:
I was able to find two workarounds for my problem, #1 being unacceptable for me and #2 I actually used:
解决方案1:使用注册表项来禁用Exchange服务器上加载停机和加载启动重新启用它。下面是示例code:
Solution #1: Use registry entries to disable exchange server on add-in shutdown and re-enable it on add-in startup. Below is sample code:
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:当用户更改的约会项目检测,并保存在用户定义的属性字段的变化。下面是示例code:
Solution #2: Detect when user changes an appointment item and save the change in user defined property field. Below is sample code:
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
感谢您大家,帮助
这篇关于VSTO:缓存Exchange模式VS LastModificationTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!