views:

43

answers:

0

Hi all,

I have written a VSTO add-in that needs to get the an appointment information from the exchange server.

On exchange (Outlook Web Access) I change a subject line of an appointment. When I see that Outlook changed the subject line to a new value, I try to grab the new value programmatically and most of the time it grabs old values, instead of the values that have appeared in Outlook.

I tried handling the ItemChange event and saving the item using .save function, but it doesn't seem to make any difference.

Does anybody know why can't I grab values from Outlook appointment programmatically as soon as they arrive to Outlook?

The code that kind of works right now, which is very ugly and which is one big work around is the following:

Public _idOfAppointmentCurrentlySyncing As New List(Of String)
Public _idOfAppointmentCurrentlySyncingNormal As New List(Of String)

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 > 3000 Then
                Dim appointmentItem As Outlook.AppointmentItem = CType(Item, Outlook.AppointmentItem)
                Dim lastModifiedDates As Date = commonToolsMethod.getAppointmentDateParameter(appointmentItem, "lastModifiedDates")
                If _idOfAppointmentCurrentlySyncing.Contains(appointmentItem.EntryID) Then
                    Dim outlookLastSyncTime As Date = commonToolsMethod.getAppointmentDateParameter(appointmentItem, "OutlookLastSyncTime")
                    If outlookLastSyncTime <> Date.MaxValue And Date.Compare(lastModifiedDates, outlookLastSyncTime) <> 0 Then
                        commonTools.addPropertyToAppointment(appointmentItem, "lastModifiedDates", outlookLastSyncTime)
                        appointmentItem.Save()
                    Else
                        _idOfAppointmentCurrentlySyncing.Remove(appointmentItem.EntryID)
                    End If
                Else
                    If _idOfAppointmentCurrentlySyncingNormal.Contains(appointmentItem.EntryID) = False Then
                        DebugWriter("Normal Save: " + appointmentItem.Start.ToString)
                        Try
                            If appointmentItem.Body <> "" Then
                                appointmentItem.Body += " "
                            End If
                        Catch ex As Exception
                        End Try
                        _idOfAppointmentCurrentlySyncingNormal.Add(appointmentItem.EntryID)
                        commonTools.addPropertyToAppointment(appointmentItem, "lastModifiedDates", dateNow.ToString)
                        appointmentItem.Save()
                        Marshal.FinalReleaseComObject(appointmentItem)
                        appointmentItem = Nothing
                        GC.Collect()
                    Else
                        _idOfAppointmentCurrentlySyncingNormal.Remove(appointmentItem.EntryID)
                    End If
                End If
            Else
                _lastFolderSwitch = _lastFolderSwitch.AddMilliseconds(100)
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Many thanks in advance.