从 FileActivated 文件访问文件夹中的所有文件 [英] Access all files in folder from FileActivated file

查看:22
本文介绍了从 FileActivated 文件访问文件夹中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个 Windows 10 通用应用程序,就像 C# 中的默认照片应用程序一样.照片应用程序允许显示用户使用照片应用程序打开文件的目录中的所有图像.但是当用户用我的应用程序打开一个文件时,我只得到 FileActivatedEventArgs 允许显示用户打开的文件.我也没有找到向用户显示该文件目录中的其他文件的解决方案.我认为问题是获得访问这些文件的权限,因为当文件的文件夹在图片库中时它可以工作.但是Windows Photo App可以在任何地方使用,所以我认为必须有一个解决方案......

I write a Windows 10 Universal App like the default Photo App in C#. The Photo App allows to show all images in the directory where the user opened the file with the Photo App. But when the user opened a file with my App I get only the FileActivatedEventArgs with allows to display the file the user opened. I found no solution to show the user the other files from the directory of this file too. I think the problem is to get the permission to access that files because when the folder of the file is in the picture library it works. But the Windows Photo App can this everywhere so I think there must be a solution ...

我试图从我的项目中提取一个非常简单的示例代码,只用几行代码显示相关部分

I have tried to extract a very simple sample code from my project that show the relevant part in only a few lines of code

public static async Task<BitmapImage> LoadImage(StorageFile file)
{
    BitmapImage bitmapImage = new BitmapImage();
    FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);
    bitmapImage.SetSource(stream);
    return bitmapImage;
}

private async void setImages(FileActivatedEventArgs args)
{
    StorageFile si = (StorageFile)App.args.Files.First();
    StorageFolder st = await si.GetParentAsync();
    StorageApplicationPermissions.FutureAccessList.Add(st);
    IReadOnlyList<StorageFile> sflist = await st.GetFilesAsync();
    foreach (StorageFile sf in sflist)
    {
        imageList.Add(await LoadImage(sf));
    }
}

推荐答案

是的,您没有对该文件夹的访问权限.在这种情况下,GetParentAsync() 可能会失败.您应该使用IFileActivatedEventArgsWithNeighboringFiles"来解析相邻文件.通过使用这个接口,OS 的 File Broker 进程将相邻的文件传递给您.

Yes, you have NO access rights for the folder. In this case, GetParentAsync() may fall. You should use "IFileActivatedEventArgsWithNeighboringFiles" to parse the neighboring files. By using this interface, OS's File Broker process passed the neighboring files to you.

https://msdn.microsoft.com/en-us/library/windows/apps/windows.applicationmodel.activation.ifileactivatedeventargswithneighboringfiles

注意 - 此 API 是从 Win8.1 添加的.而且,Win8.0 版本的照片应用程序在被 FileActivated 激活时无法显示相邻文件.Win8.1 版本的 Photo 应用程序可以使用此 API.

Note - This API was added from Win8.1. And, Win8.0 ver of Photo app can't show the neighboring files when it was activated by FileActivated. Win8.1 ver of Photo app may use this API.

这篇关于从 FileActivated 文件访问文件夹中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆