Question

In the file picker Windows 8 sample a file is saved like this:

CachedFileManager.DeferUpdates(file);
await FileIO.WriteTextAsync(file, stringContent);
FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);

I'm serialising an object as XML so doing it slightly differently:

// CachedFileManager.DeferUpdates(file);
var ras = await file.OpenAsync(FileAccessMode.ReadWrite);
var outStream = ras.GetOutputStreamAt(0);
var serializer = new XMLSerializer();
serializer.Write(myObject, outStream);
// FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);

It works with or without the CachedFileManager (commented out above).

So, should I include the CachedFileManager and if I do use it am I saving the file in the right way.

This code works and saves the file fine, but I don't like including code that I don't understand.

Was it helpful?

Solution

Yes, this code will work without CachedFileManager. But, when you use CachedFileManager, you inform the file provider that the file is in process of change. If your file is located on SkyDrive it is faster to create a file and upload it at once instead of update it multiple times.

OTHER TIPS

You can have the full story there : http://www.jonathanantoine.com/2013/03/25/win8-the-cached-file-updater-contract-or-how-to-make-more-useful-the-file-save-picker-contract/

It simply tells the "repository" app to upload the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top