Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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# 试图保存由FileOpenPicker选择并由FileSavePicker保存的图片的副本_C#_Uwp_Windows Store Apps - Fatal编程技术网

C# 试图保存由FileOpenPicker选择并由FileSavePicker保存的图片的副本

C# 试图保存由FileOpenPicker选择并由FileSavePicker保存的图片的副本,c#,uwp,windows-store-apps,C#,Uwp,Windows Store Apps,这是迄今为止我拥有的打开图片并试图保存它的代码 任何关于它为什么不起作用的信息都将非常感谢 FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation =PickerLocationId.PicturesLibrary; openP

这是迄今为止我拥有的打开图片并试图保存它的代码 任何关于它为什么不起作用的信息都将非常感谢

        FileOpenPicker openPicker = new FileOpenPicker();
        openPicker.ViewMode = PickerViewMode.Thumbnail;
        openPicker.SuggestedStartLocation =PickerLocationId.PicturesLibrary;
        openPicker.FileTypeFilter.Add(".jpg");
        openPicker.FileTypeFilter.Add(".jpeg");
        openPicker.FileTypeFilter.Add(".png");

        StorageFile file = await openPicker.PickSingleFileAsync();
        if (file != null)
        {



            FileSavePicker savePicker = new FileSavePicker();
            savePicker.SuggestedStartLocation = 
             PickerLocationId.PicturesLibrary;
            savePicker.FileTypeChoices.Add("jpeg image", new List<string>() 
            { ".jpg" });
            savePicker.SuggestedFileName = "Photo";

            string token = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
            StorageFile SaveFile = await StorageApplicationPermissions.FutureAccessList.GetFileAsync(token);

            StorageFile savefile = await savePicker.PickSaveFileAsync();

            if (SaveFile != null)
            {
                 await FileIO.WriteTextAsync(SaveFile, SaveFile.Name);
            }

        }
FileOpenPicker-openPicker=newfileopenpicker();
openPicker.ViewMode=PickerViewMode.缩略图;
openPicker.SuggestedStartLocation=PickerLocationId.PicturesLibrary;
openPicker.FileTypeFilter.Add(“.jpg”);
openPicker.FileTypeFilter.Add(“.jpeg”);
openPicker.FileTypeFilter.Add(“.png”);
StorageFile文件=等待openPicker.PickSingleFileAsync();
如果(文件!=null)
{
FileSavePicker savePicker=新FileSavePicker();
savePicker.SuggestedStartLocation=
PickerLocationId.PicturesLibrary;
savePicker.FileTypeChoices.Add(“jpeg图像”,新列表()
{.jpg});
savePicker.SuggestedFileName=“Photo”;
string token=Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(文件);
StorageFile SaveFile=等待StorageApplicationPermissions.FutureAccessList.GetFileAsync(令牌);
StorageFile savefile=wait savePicker.PickSaveFileAsync();
if(SaveFile!=null)
{
等待FileIO.WriteTextAsync(SaveFile,SaveFile.Name);
}
}

将打开的文件存储到
FutureAccessList
中,然后立即将其作为
SaveFile
变量检索。就在下面,您创建了一个
saveFile
,我想这是您想要使用的,但是在
WriteTextAsync
方法中,您将
saveFile
作为目标,而不是
saveFile


您肯定应该改进您的命名约定,只有大小写不同的两个变量很容易出错。此外,局部变量应始终以小写字母开头。

“为什么它不起作用”-您需要向我们提供有关该问题的更多信息。例如,您在保存时是否看到任何错误?或者,当您尝试保存文件时,应用程序是否停止响应?您有两个名为
SaveFile
SaveFile
StorageFile
。。。你想保存到哪一个?