C#如何在FileSavePicker之后保存MemoryStream

时间:2014-04-28 13:13:49

标签: c# silverlight windows-phone-8.1

我有一个应用程序Windows Phone 8.1 Silverlight,我使用FileSavePicker。但我找不到保存MemoryString的示例。这是我在PickSaveFileAndContinue()之后的代码; 谢谢你的帮助!

    public async void ContinueFileOpenPicker(FileSavePickerContinuationEventArgs args)
    {
        if ((args.ContinuationData["Operation"] as string) == "UpdateProfilePicture" && args.File != null)
        {
            var file = args.File;
            using (IRandomAccessStream tileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
            {
                //GiveMyPhoto() is a method who return my MemoryStream


                (App.Current as App).FilePickerContinuationArgs = null;
            }
        }
    }

1 个答案:

答案 0 :(得分:2)

您的var file实际上是StorageFile fileWindows.Storage.FileIO命名空间可以满足您的所有需求。

实施例

MemoryStream stream = GiveMyPhoto();

await Windows.Storage.FileIO.WriteBufferAsync(file, stream.GetWindowsRuntimeBuffer(0,(int)stream.Length));