Thursday, April 15, 2010

WP7 IsolatedStorage Backup/Restore

One of the drawbacks of the WP7 Emulator is that it doesn't save the state between sessions and also it is difficult to deploy a file with your project and then use it. This means that every time you start a new session of the emulator you loose all the data on the IsolatedStorage.
I've developed a small solution (there is room for improvement) for backing-up and restoring the files (folder structure included) of the IsolatedStorage. It is using an WCF service that stores/sends file content from/to the IsolatedStorage in/from a folder named Backup located in the WCF project folder. For optimizing the communication the service uses binaryMessageEncoding. It also splits the files in 100Kbytes parts (you can modify this size from the source code if you want bigger parts- it will be faster) .
The solution is easy to use even if it took me a lot of time to make it work (especially the readerQuotas, maxBufferSize, maxStringContentLength). In fact I was having "fun" with it at 3 o'clock in the morning. If you want to backup your IsolatedStorage just hit backup and it will write the content of IsolateStorage in the Backup folder of the pc. If you want to restore/copy files to the IsolatedStorage copy the files/folders you want to the Backup folder of the PC and then hit Restore and it will copy all the data to the IsolatedStorage.

Hope you'll like it! Don't forget to modify the ServiceReferences.ClientConfig before you run the project



























As usual you can download the Source code

6 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. Could you comment about what configuration changes you made to either or both IIS and WCF to avoid getting "400" errors?

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete
  4. This comment has been removed by a blog administrator.

    ReplyDelete
  5. Hi,

    I am trying to use your sample and after a bit of tinkering I got it working so that it backs up the files accross the internet to my webserver. On Restore I get an error
    Cannot implicitly convert type 'System.Collections.ObjectModel.ObservableCollection' to 'BackupRestore.FileTransferRef.serverFile[]'

    this error happens in the fClient_GetServerFilesCompleted eventhandler in the line
    restoreFiles = e.Result;

    any idea how to fix it?

    thanks

    Mike

    ReplyDelete
  6. Figured it out.
    I had to change the definition of the serverFile[] to
    ObservableCollection restoreFiles;
    tweak the Length Propery to the Count Property and voila it worked

    ReplyDelete