2010-02-18 17 views
0

我正在開發一個依靠Outlook Appointment的LastModificationTime屬性的VSTO Outlook加載項。問題是當緩存交換模式打開時,LastModificationTime屬性會在每次關閉Outlook時自動更新。有沒有可能的解決方案,我可以用它來獲取用戶更改約會時的日期和時間,而不是緩存交換模式更改約會時的日期和時間?VSTO:緩存交換模式VS LastModificationTime

看到,有沒有很多的回答,我想更詳細地描述我的問題 - 這是發生了什麼:

  1. 我更改項目(異常行爲只發生在我已經改變了項目)
  2. LastModificationTime更改爲我保存該項目的時間(我看到OutlookSpy的更改)。 (如LastModificationTime下午3點30分零零秒)
  3. 我的工作,直到下午4點00分零零秒,並檢查LastModificationTime,它仍然顯示下午3點30分零零秒
  4. 我關閉Outlook
  5. 我打開Outlook檢查LastModificationTime。現在LastModificationTime顯示3:30:42而不是3:30:00。 爲什麼我在重新打開Outlook後又增加了42秒?

謝謝你的任何建議,你可以給我。

+0

MMB我沒有得到這個...你還有什麼在Outlook中運行。 – 76mel 2010-02-22 17:45:23

+0

76mel,我也不明白,爲什麼我問這個問題。我還有幾個在Outlook中運行的addIns,我嘗試禁用所有這些,但它沒有改變。 – 2010-02-22 20:10:30

+0

我在頂部的描述中添加了關於我的問題性質的更多解釋。 – 2010-02-22 20:27:56

回答

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 

謝謝大家,幫