C# FileOpenPicker+;Facebook+;OpenAsync抛出FileNotFoundException

C# FileOpenPicker+;Facebook+;OpenAsync抛出FileNotFoundException,c#,xaml,windows-8,microsoft-metro,C#,Xaml,Windows 8,Microsoft Metro,我对FileOpenPicker(ModernUI xaml/c#)有问题,因为如果从web上拾取一些图片,它会返回“StorageFile”,不会出错,但当我尝试使用OpenAsync打开它时,系统会抛出FileNotFoundException。我特别注意到,在从facebook上获取旧图片时,这种情况经常发生 通过使用,很容易重现该问题。只需启动应用程序,从“Facebook”中选取一些图片,并确保选取一些旧图片,因为我注意到最新的一张正在正常打开 更具体地说,请找到真正抛出该异常的代码的

我对FileOpenPicker(ModernUI xaml/c#)有问题,因为如果从web上拾取一些图片,它会返回“StorageFile”,不会出错,但当我尝试使用OpenAsync打开它时,系统会抛出FileNotFoundException。我特别注意到,在从facebook上获取旧图片时,这种情况经常发生

通过使用,很容易重现该问题。只需启动应用程序,从“Facebook”中选取一些图片,并确保选取一些旧图片,因为我注意到最新的一张正在正常打开

更具体地说,请找到真正抛出该异常的代码的和平:

    // Open a stream for the selected file
    StorageFile file = await open.PickSingleFileAsync();

    // Ensure a file was selected
    if (file != null)
    {
        // Ensure the stream is disposed once the image is loaded
        // !!! Here exception is thrown if you pickup some old file from facebook !!!
        using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
        {
            // Set the image source to the selected bitmap
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.DecodePixelHeight = decodePixelHeight;
            bitmapImage.DecodePixelWidth = decodePixelWidth;

            await bitmapImage.SetSourceAsync(fileStream);
            Scenario2Image.Source = bitmapImage;
        }
    }
提前感谢您的建议和帮助

问候

MG

好的,就这样:)

当你下载一个文件并将其保存在光盘上的某个位置时,你将无法打开它,因为位置不是应用程序中的功能,请记住,Windows应用商店应用程序是沙盒式的,因此它们只能获取功能中的内容

您可以通过两种方式处理此“问题”

1) 将文件保存在应用程序可以访问的位置之一: ->文档库 ->音乐图书馆 ->视频库 ->图像库 ->本地应用程序目录

可以在应用程序始终访问的本地应用程序目录的功能中设置库。从这些目录中,您可以轻松地打开文件

2) 将路径保存到acces缓存中的文件 你可以这样做

StorageApplicationPermissions.FutureAccessList.AddOrReplace(fol.GetHashCode().ToString(), fol);
之后,您可以访问该目录,即使它不在您的功能范围内,但请记住,缓存可以包含1000个目录