Deleted Files Not Refreshed RRS feed

  • Question

  • I have two directories, one on the network, the other on a local drive.  I want the local drive directory (local directory) to mirror what is on the network directory (remote directory) at all times.  The problem is that if I delete files on the local directory and then perform the below code, even though the files remain on the remote directory, they are not refreshed in the local directory.  The only way that I can seem to make this perform as I want is to first delete the filesync.metadata file in the local directory.  Then it works perfectly, although this seems a bit kludgey.  Is there something I am doing wrong here?  I've tried all combinations of file sync options, all with the same result.  I have tried the code with and without the loop at the bottom, still the same result.

    Dim SourceFolder As FileSyncProvider
    Dim DestinationFolder As FileSyncProvider
    Dim Orchestrator As SyncOrchestrator
    Dim ScopeFilter As FileSyncScopeFilter
    Dim returnvalue As SyncOperationStatistics

                ScopeFilter = New FileSyncScopeFilter
                SourceFolder = New FileSyncProvider(Me.txtDirectoryFrom.Text, ScopeFilter, FileSyncOptions.CompareFileStreams)
                DestinationFolder = New FileSyncProvider(Me.txtDirectoryTo.Text, ScopeFilter, FileSyncOptions.CompareFileStreams)

                Orchestrator = New SyncOrchestrator
                Orchestrator.LocalProvider = DestinationFolder
                Orchestrator.RemoteProvider = SourceFolder
                Orchestrator.Direction = SyncDirectionOrder.Download
                returnvalue = Orchestrator.Synchronize()
                Do While returnvalue.DownloadChangesFailed > 0
                    returnvalue = Orchestrator.Synchronize

    Wednesday, February 17, 2010 4:22 PM


  • I think what you have observed is the designed behavior.  

    After you setup the initial file sync, files are looking convergent on each side.  However when the sync direction is Download,  it means it only sync file changes on the remote share and to the local folder, and not affected by the local changes.  In another word, as long as no change on the remote side, you won't see anything in the sync.  Once you delete filesync.metadata and do sync, it pretty much means you start over the sync from the very beginning, so the remote files are all downloaded to the local side.

    In the situation as you have described - you would like to get all files if they are locally deleted from the remote.  Then you need to find out which files are deleted and dummy modified the corresponding files on the remote.  In this case, the next file sync will sync all these changes to the local folder, but you may see UPDATE/DELETE conflict in general.  So just resolve as the SOURCE win or REMOTE win.

    Now question goes to how to detect the locally deleted files.  You need to create a different sync app which will "Pretend" to sync from local side the remote side (Just reverse the local provider and remote provider in your existing app).  However you need to ensure "PreviewMode" is set on both providers.  Otherwise the local file delete will happen on the remote side.  Subscribe to ApplyingChange event and from the event argument, you can find out the file name and change type (DELETE/UPDATE/CREATE).  Again, please use Preview mode.

    Leo Zhou ------ This posting is provided "AS IS" with no warranties, and confers no rights.
    • Proposed as answer by L Zhou [MSFT]Editor Wednesday, February 17, 2010 6:01 PM
    • Marked as answer by Yunwen Bai Thursday, February 18, 2010 9:28 PM
    Wednesday, February 17, 2010 5:44 PM