10的Windows通用应用程序文件/目录访问 [英] Windows 10 Universal App File/Directory Access
问题描述
I'm开发一个应用程序,从文件系统上的一个可配置的位置读取JPEG和PDF文件。
目前,在WPF实现,现在我正尝试移动到新的Windows应用程序的通用正在运行的版本。
I´m developing an app that is reading jpeg and pdf files from a configurable location on the filesystem. Currently there is a running version implemented in WPF and now I´m trying to move to the new Windows Universal apps.
以下code正常工作与WPF:
The following code works fine with WPF:
public IList<string> GetFilesByNumber(string path, string number)
{
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentNullException(nameof(path));
if (string.IsNullOrWhiteSpace(number))
throw new ArgumentNullException(nameof(number));
if (!Directory.Exists(path))
throw new DirectoryNotFoundException(path);
var files = Directory.GetFiles(path, "*" + number + "*",
SearchOption.AllDirectories);
if (files == null || files.Length == 0)
return null;
return files;
}
通过使用通用应用程序我碰到了一些问题:
With using Universal Apps I ran into some problems:
-
Directory.Exists
不可用 - 如何从目录中我的应用程序存储的外部读取?
要在应用程序存储外的其他目录下读取我试过如下:
To read from an other directory outside the app storage I tried the following:
StorageFolder folder = StorageFolder.GetFolderFromPathAsync("D:\\texts\\");
var fileTypeFilter = new string[] { ".pdf", ".jpg" };
QueryOptions queryOptions = new QueryOptions(CommonFileQuery.OrderBySearchRank, fileTypeFilter);
queryOptions.UserSearchFilter = "142";
StorageFileQueryResult queryResult = folder.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> files = queryResult.GetFilesAsync().GetResults();
问题是:它isn't工作,但我得到一个异常:
The thing is: It isn´t working, but I get an exception:
型System.UnauthorizedAccessException的的异常出现在TextManager.Universal.DataAccess.dll但在用户code没有处理
其他信息:访问被拒绝。 (从HRESULT异常:0X80070005(E_ACCESSDENIED))
An exception of type 'System.UnauthorizedAccessException' occurred in TextManager.Universal.DataAccess.dll but was not handled in user code Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
我知道,你必须在清单中配置一些权限,但我不能找到文件系统的IO操作的一个合适的...
I know that you have to configure some permissions in the manifest, but I can´t find one suitable for filesystem IO operations...
是不是有人也有这样的问题/一个可能的解决方案?
Did someone also have such problems/a possible solution?
解决方案:
从@Rico苏特给我的解决方案,我与FolderPicker组合chosed的FutureAccessList。另外,也可以与令牌以访问条目重新启动该程序后
Solution: From the solutions that @Rico Suter gave me, I chosed the FutureAccessList in combination with the FolderPicker. It is also possible to access the entry with the Token after the program was restarted.
我也可以推荐你 UX Guidlines 这<一个href=\"https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/FileSearch/cs/Scenario1.xaml.cs\">Github样品。
非常感谢你!
推荐答案
在UWP的应用程序,你只能访问下列文件和文件夹:
In UWP apps, you can only access the following files and folders:
- 这是在清单文件目录(例如,文档,图片,影片文件夹)
- 文件从<一个href=\"https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.accesscache.storageapplicationpermissions.aspx\">FutureAccessList或MostRecentlyUsedList
- 文件,这些文件与文件扩展名关联,或通过共享 打开
其中用户手动与 FileOpenPicker 或的目录和文件: //msdn.microsoft.com/library/windows/apps/br207881\">FolderPicker
- Directories which are declared in the manifest file (e.g. Documents, Pictures, Videos folder)
- Directories and files which the user manually selected with the FileOpenPicker or FolderPicker
- Files from the FutureAccessList or MostRecentlyUsedList
- Files which are opened with a file extension association or via sharing
如果您需要访问所有文件 D:\\
,用户必须手动挑选 D:\\
开车使用FolderPicker,那么你获得的一切在此驱动器...
If you need access to all files in D:\
, the user must manually pick the D:\
drive using the FolderPicker, then you have access to everything in this drive...
这篇关于10的Windows通用应用程序文件/目录访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!