dot.net Magazin 5.08 Sync Framework Article and File Sync with VB.net

Imports Microsoft.Synchronization
Imports Microsoft.Synchronization.Files
Imports System.IO

Module Module1

Sub Main()

'Define directories
Dim _sourceDir As String = "c:\\temp\\1"
Dim _destDir As String = "c:\\temp\\2"

'Define system ids
Dim _sourceId As SyncId = New SyncId(New Guid("A4715EAF-341E-4ebf-90C3-71E8644CA6E8"))
Dim _destId As SyncId = New SyncId(New Guid("FF766014-0DA4-401d-BDA1-0679326ECF96"))

'Exclude some patterns
Dim _syncFilter As FileSyncScopeFilter = New FileSyncScopeFilter()
_syncFilter.AttributeExcludeMask = FileAttributes.Hidden Or FileAttributes.System
_syncFilter.FileNameExcludes.Add("DoNotCopy.txt")
_syncFilter.SubdirectoryExcludes.Add("DoNotCopy")

'Setup options (makes sure files aren't deleted for ever)
Dim _syncOptions As FileSyncOptions = FileSyncOptions.RecycleDeletes Or FileSyncOptions.RecycleOverwrites

'Do the sync
Using _sourceProvider As FileSyncProvider = New FileSyncProvider(_sourceId, _sourceDir, _syncFilter, _syncOptions)
Using _destinationProvider As FileSyncProvider = New FileSyncProvider(_destId, _destDir, _syncFilter, _syncOptions)

Dim _syncAgent As SyncAgent = New SyncAgent()
_syncAgent.LocalProvider = _sourceProvider
_syncAgent.RemoteProvider = _destinationProvider
_syncAgent.Direction = SyncDirection.UploadAndDownload
_syncAgent.Synchronize()

End Using
End Using

End Sub

End Module