0

In my App i'm using a a FileSavePicker Contract (Provider). So other Apps could save files to my App. I implemented it, as it is shown on MSDN. The Problem now is, that i have to process a "saved" file, but how do i know, when the saving is completed? Here is my handler

private async void FileSavePickerUI_TargetFileRequested(FileSavePickerUI sender, TargetFileRequestedEventArgs args)
{
        var deferral = args.Request.GetDeferral();

        string saveFileName = sender.FileName;

        StorageFolder fileSavePickerContractTempFolder = await ApplicationData.Current.LocalCacheFolder.CreateFolderAsync("FileSavePickerContract", CreationCollisionOption.OpenIfExists);

        StorageFile fileSavePickerContractTempFile = await fileSavePickerContractTempFolder.CreateFileAsync(saveFileName, CreationCollisionOption.ReplaceExisting);

        args.Request.TargetFile = fileSavePickerContractTempFile;

        deferral.Complete();
    }

Target of my app is the anniversary update (1607). After deferral.Complete() i Need to to more work with that file for integrating in my App. Can someone Point me in the right direction?

andy
  • 509
  • 1
  • 8
  • 21
  • use `await fileSavePickerContractTempFolder.CreateFileAsync().ContinueWith((s,a)=> { })` – AVK Jan 11 '17 at 16:27
  • IAsyncOperation does not contain a Definition for 'ContinueWith' – andy Jan 11 '17 at 16:48
  • Try this and see if it works? `StorageFile fileSavePickerContractTempFile = await fileSavePickerContractTempFolder.CreateFileAsync(saveFileName, CreationCollisionOption.ReplaceExisting).AsTask().ContinueWith((file) => { return file.Result; });` – AVK Jan 11 '17 at 17:13
  • Did also not work. On the "", i call a method and pass the StorageFile in, but the StorageFile has even 0bytes at this Point. – andy Jan 11 '17 at 17:34
  • No more ideas to this Problem? – andy Jan 14 '17 at 15:25
  • I have now implemented a CachedFileUpdater which triggers the "OnCacheFileUpdaterActivated" Event in App.xaml.cs. From there i can work with the complete file. But if i Launch my app after that and will Close it, a Dialog says: "You are using TestApp in another App for saving a file. If you Close TestApp, the file may not be saved". So i think i Need to Report the successful saving somehow, because the file is saved completely. Any suggestions? – andy Jan 15 '17 at 11:35

2 Answers2

1

With the CacheFileUpdater i can react to the file, as soon it is written completely

CachedFileUpdater.SetUpdateInformation(fileSavePickerContractTempFile, url, ReadActivationMode.NotNeeded, WriteActivationMode.AfterWrite, CachedFileOptions.None);

On App.xaml.cs i override now the "OnCachedFileUpdaterActivated" Event, in which i can perform some Actions with the completely written file. So this works now as expected.

BUT! This does not work on Windows 10 Mobile, there the OnCachedFileUpdaterActivated EventHandler on App.xaml.cs gets not fired, why is this?

andy
  • 509
  • 1
  • 8
  • 21
  • Can nobody help me out with this problem? – andy Jan 19 '17 at 08:33
  • I have the same issue. Don't know how to fix it. The DropBox app works somehow, but not mine. DropBox did the same thing (some time ago): http://www.jonathanantoine.com/2013/03/25/win8-the-cached-file-updater-contract-or-how-to-make-more-useful-the-file-save-picker-contract/ – André Fiedler Apr 03 '17 at 20:56
0

Your file is saved after the line with await CreateFileAsync. Method CreateFileAsync by itself returns IAsyncOperation, if you await it, the next line after await will be executed when this operation completes.

xill47
  • 77
  • 5