Implementing an OnSyncSave Event Sink
Topic Last Modified: 2006-06-12
A synchronous event is called once for the beginning phase of the specified event and then again to either commit or abort it. The EVT_NEW_ITEM flag is set for the first time this specific event is called for this event registration. See Store Event Sink Bit Flags for more information.
Example
Visual Basic
Private Sub IExStoreSyncEvents_OnSyncSave(ByVal pEventInfo As Exoledb.IExStoreEventInfo, ByVal bstrURLItem As String, ByVal lFlags As Long)
Dim FSO As Object
Dim EvtLog As String
Dim EvtFile
Dim DispEvtInfo As IExStoreDispEventInfo
Dim ADODBRec As ADODB.Record
Set DispEvtInfo = pEventInfo
'Log file
EvtLog = Environ("SystemDrive") & "\OnSyncSave.log"
'Creates new log file %SystemDrive%\OnSyncSave.log or opens it if exists
Set FSO = CreateObject("Scripting.FileSystemObject")
Set EvtFile = FSO.OpenTextFile(EvtLog, 8, True)
'Append incoming event info into log file
EvtFile.WriteLine ("[VB Event Sink] OnSyncSave()")
EvtFile.WriteLine (" URL Item: " & bstrURLItem)
EvtFile.WriteLine (" lFlags: " & "0x" & Hex(lFlags))
'Small sample that shows how to use ADO Record Object and Fields inside events
Set ADODBRec = DispEvtInfo.EventRecord
EvtFile.WriteLine (" DAV:Displayname Value: " & ADODBRec.Fields("DAV:displayname").Value)
'To determine type of incoming OnSyncSave notifications:
'Case 1: EVT_SYNC_BEGIN
If lFlags And EVT_SYNC_BEGIN Then
'Perform your tasks
'Begin phase of OnSyncSave for a resource
EvtFile.WriteLine (" Flag contains EVT_SYNC_BEGIN bit set")
'Case 2: EVT_SYNC_COMMITTED
ElseIf lFlags And EVT_SYNC_COMMITTED Then
'Perform your tasks
'Commit phase of OnSyncSave for a resource
EvtFile.WriteLine (" Flag contains EVT_SYNC_COMMITTED bit set")
'Case 3: EVT_SYNC_ABORTED
ElseIf lFlags And EVT_SYNC_ABORTED Then
'Perform your tasks
'Abort phase of OnSyncSave for item that is getting aborted
EvtFile.WriteLine (" Flag contains EVT_SYNC_ABORTED bit set")
End If
'To determine cause of OnSyncSave
'Case 1: EVT_IS_DELIVERED
If lFlags And EVT_IS_DELIVERED Then
'Perform your tasks
'OnSyncSave for delivered mail item
EvtFile.WriteLine (" Flag contains EVT_IS_DELIVERED bit set")
'Case 2: EVT_MOVE
ElseIf lFlags And EVT_MOVE Then
'Perform your tasks
'OnSyncSave for moved item
EvtFile.WriteLine (" Flag contains EVT_MOVE bit set")
'Case 3: EVT_COPY
ElseIf lFlags And EVT_COPY Then
'Perform your tasks
'OnSyncSave for copied item
EvtFile.WriteLine (" Flag contains EVT_COPY bit set")
End If
'Check if it is folder notification
If lFlags And &H2 Then
'Perform your tasks
'OnSyncSave for a folder
EvtFile.WriteLine (" Flag contains EVT_IS_COLLECTION bit set")
End If
EvtFile.WriteBlankLines (1)
'Before Quit
EvtFile.Close
Set FSO = Nothing
Set DispEvtInfo = Nothing
End Sub