UWP FileSavePicker Contract File Processing

2019-09-07 02:24发布

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?

2条回答
一纸荒年 Trace。
2楼-- · 2019-09-07 03:14

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?

查看更多
劳资没心,怎么记你
3楼-- · 2019-09-07 03:29

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.

查看更多
登录 后发表回答