Magazin 5.08 Sync Framework Article and File Sync with

This morning I finally got my authors copy of the Magazin that I wrote an article on Microsoft Sync Framework. It’s in german, 7 pages long and you can buy it tomorrow.

Anyhow, I got an email this morning asking about one of the code listings and asking if there was anything different to do in It’s been a while since I last did (I actually did more VB6 than but I converted the sample from the magazine to Just remember to reference Microsoft.Synchronization and Microsoft.Synchronization.Files.

(By the way I still haven’t got round to looking at CTP2 of the Sync Framework. All this stuff (and the article) applies to CTP1. Maybe there was a breaking change in CTP2 with regard to the FileSyncProvider. I must get round to looking at CTP2 a.s.a.p.)

Here is the code:

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

        '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

            End Using
        End Using

    End Sub

End Module


One thought on “ Magazin 5.08 Sync Framework Article and File Sync with

  1. Sehr geehrter Herr Duggleby,

    ich bin Abonnent des dot.Net Amgazins und habe mit Interesse den Artikel Magazin 5.08 Sync Framework Article and File Sync with gelesen.

    Da ich jetzt auch über VS 2008 verfüge, wollte ich das Synchronisieren gleich mal ausprobieren.

    Hierzu habe ich eine kurze Frage.

    Ich will das Framework für die Synchronisation unsere SQL Server 2005 Webdatenbank mit unserer SQL Server 2005 Inhouse Datenbank verwenden.

    Bis jetzt hat mir der Assistent immer eine .sdf Datei beim Client angelegt.

    Geht die Synchronisation auch direkt zwischen zwei vollwertigen SQL Servern?
    Ist das Framework dafür ausgelegt?
    Brauch ich dann die .sdf überhaupt?

    Wie kann ich das bewerkstelligen?

    Gibt es ggf. bessere Alternativen als das Framework?
    Ich will die Daten dabei auch bidirektional abgleichen.

    Vielen Dank im voraus für ihre Antwort.

    Mit freundlichen Grüßen

    Rene Wack

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.