Synchronize files/folders programmatically

K

Krupa

Hi All,

I am trying to write a C# .Net desktop application that synchronizes
files/folders on the PC with those on a Windows CE device, when the
device is connected to the PC via ActiveSync.

My requirement is to automatically synchronize a folder on the device
(on storage card) with a folder on the computer. I looked at the
OpenNETCF.Communications library used the CopyFileFromDevice and
CopyFileToDevice functions in it. But I didn't find any function that
would synchronize files/folders. Do I need to look somewhere else?

Thanks,
Krupa
 
P

Paul G. Tobey [eMVP]

What do you mean by "synchronize"? ActiveSync will do this for you for
Pocket PC devices, although you may not like its choice of folders. It's
deciding, one file at a time, whether the version on the PC is newer, older
or the same and copying the file in the right direction as appropriate.
There's no SynchronizeFolder() API call. You have to iterate over the files
that you want to look at and decide, based on some criteria that you will
come up with yourself, what to do.

CeFindAllFiles (or CeFindFirstFile, CeFindNextFile) and look at the
date/time information (which may or may not be useful for telling if the
file is newer or older), the content of the file (CeCreateFile, CeReadFile),
etc.

Paul T.
 
G

Guest

In C# there's no inherent way to do this. Syncing is a complex issue - you
have to look at changes, conflict resolution, and a lot of other things. An
ActiveSync service provider has thins for native code (and it's no small
thing to use that either).
 
K

Krupa

Thanks Chris!

By "synchronize" I meant update files/folders on the device only if
they are differet from those on the computer. I just wanted to avoid
copying/overwriting all the files on the device or going through the
files/folders individually. I wanted to know if there was any
synchronization function available in opennetcf. As you said, I don't
want to go with ActiveSync synchronization as it is limited to only My
Documents folder on the device, where as I want to synchronize the
storage card.

Looks like going through individual files and checking if they need to
be updated is the only way for me now.
 
G

Guest

Yes, and it's still not simple. For example, what constitues a "change"? A
date difference? A size difference? Actual data difference? How do you
which was changed (device or PC)? What if the date/time on the device
doesn't match the PC? What happens if the file was changed on both ends?
How do you detect that, and how do you resolve it?

Synchronization is a huge task - even for simple items.
 
K

Krupa

Actually I don't need synchronization in both ways. I just need to
update files/folders on the device, whenevre files are changed on the
PC and don't need to do the other way. This makes my job slightly
easier.

I am thinking about adding an attribute to all the files (like a
timestamp). I plan to change it each time I update it on the PC. That
way I can compare the attribute of the file on the PC with that of the
file on the device and update the files on the device if needed. Do you
think this is a good approach? If yes, what is the best way to
add/change file attributes?
 
G

Guest

There's no way to easily add a file attribute. Your best bet is to keep a
sync log on the device that knows what PC files have been "synced" and what
the remote file attributes were at the last sync. I'd probably store size,
modify date and CRC.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top