我在使用FileOpenPicker (ModernUI xaml/c#)时遇到了问题,因为如果是从网络上挑选的一些图片,它会返回"StorageFile“而不会出错,但当我尝试用OpenAsync打开它时,系统会抛出FileNotFoundException。特别是,我注意到,在从facebook上拾取旧照片的情况下,这种情况总是发生。
使用SDK Sample app "XAML images sample"可以很容易地重现这个问题。只需启动应用程序并从"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;
}
}提前感谢您的建议和帮助
亲切的问候
毫克
发布于 2012-11-16 21:23:11
好的,开始吧:)
当你下载一个文件并将其保存在光盘上的某个地方时,你将在关闭它后无法打开它,因为位置不在应用程序功能中。请记住,Windows应用商店应用程序是沙箱的,所以它们只能获得功能中的内容。
你可以用两种方法来解决这个“问题”。
1)将文件保存在您的应用程序可以访问的位置之一:->文档库->音乐库->视频库->图像库->本地应用程序目录
库可以在功能中设置为您的应用程序始终访问的本地应用程序目录。从这些目录中,您可以轻松地打开文件
2)将文件的路径保存在acces缓存中,可以这样做
StorageApplicationPermissions.FutureAccessList.AddOrReplace(fol.GetHashCode().ToString(), fol);之后,即使该目录不在您的功能范围内,您也可以访问该目录,但请记住,缓存可以包含1000个目录
https://stackoverflow.com/questions/13415543
复制相似问题