Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows Phone 8.1 RT PickSaveFileAndContinue()方法创建一个空文件_C#_Windows Runtime_Windows Phone 8.1_Filesavepicker - Fatal编程技术网

C# Windows Phone 8.1 RT PickSaveFileAndContinue()方法创建一个空文件

C# Windows Phone 8.1 RT PickSaveFileAndContinue()方法创建一个空文件,c#,windows-runtime,windows-phone-8.1,filesavepicker,C#,Windows Runtime,Windows Phone 8.1,Filesavepicker,我正在尝试使用WP 8.1 RT中的PickSaveFileAndContinue()方法将文件保存到Documents文件夹。除保存的文件为空外,一切都正常。 当我在OnActivated()方法中从以下代码返回文件时,它的大小为零 有人吗 var database = await FileHelper.GetFileAsync(ApplicationData.Current.LocalFolder, DATABASE_NAME); FileSavePicker savePicker =

我正在尝试使用WP 8.1 RT中的PickSaveFileAndContinue()方法将文件保存到Documents文件夹。除保存的文件为空外,一切都正常。 当我在OnActivated()方法中从以下代码返回文件时,它的大小为零

有人吗

var database = await    FileHelper.GetFileAsync(ApplicationData.Current.LocalFolder, DATABASE_NAME);
FileSavePicker savePicker = new FileSavePicker();
savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
savePicker.FileTypeChoices.Add("Database File", new List<string>() { ".db" });
savePicker.DefaultFileExtension = ".db";
savePicker.SuggestedFileName = DATABASE_NAME;
savePicker.SuggestedSaveFile = database;

这是意料之中的。PickSaveFileAndContinue不知道应用程序要保存什么。它只提供一个空的存储文件。然后,应用程序可以将它想要保存的任何内容写入文件。

为什么?我正在指定要保存的存储文件。请参考编辑后的问题。
 protected async override void OnActivated(IActivatedEventArgs args)
    {
        byte[] buffer = null;
        if(args!=null)
        {
            if(args.Kind == ActivationKind.PickSaveFileContinuation)
            {
                var file = ((FileSavePickerContinuationEventArgs)args).File;//This is empty
                using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
                {
                    buffer = new byte[stream.Size];
                    using (DataReader reader = new DataReader(stream))
                    {
                        await reader.LoadAsync((uint)stream.Size);
                        reader.ReadBytes(buffer);
                    }
                }

                if (file != null)
                {
                    CachedFileManager.DeferUpdates(file);
                    await FileIO.WriteBytesAsync(file, buffer);
                    Windows.Storage.Provider.FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
                }
            }
        }
        base.OnActivated(args);
    }