I don't know anything about this method but the error itself indicates you are using query options that are invalid. Looking at the documentation for the method I notice it is inconsistent as to what is allowed making this really hard to figure out. However it does mention the AreQueryOptionsSupported method that you can call to confirm that the options you want to use are valid for the given folder. I recommend you call this method with your configured options first and see if it returns success. If it says they are valid then the subsequent call should be fine. If not then your query options are incorrect for the folder you're trying to use.
[UWP] Item Count Exception
when i am trying to use Search Query Options & get items count from AppData folder (Path: C:\Users\mine\AppData\Local\Packages) an exception, please see attached image,
not sure what is the issue with my code, any clue ?
2 answers
Sort by: Most helpful
-
-
Junjie Zhu - MSFT 14,526 Reputation points Microsoft Vendor
2023-04-14T10:00:20.36+00:00 I have discussed with the team, and this is by desgin.
Access to C:\Users\UserName\AppData\Local\Packages, this is not allowed because this is where all of the other UWP applications are located. It wouldn't make sense for System to allow App-container to do this.
If you want to access to your own application folder, you can simply specify
ApplicationData.Current.LocalFolder
as the folder or other folders in your app folder.var folder = ApplicationData.Current.LocalFolder; await folderPicker.PickSingleFolderAsync(); var ImageFileTyptes = new List<string> { ".jpg" }; var ImageSearchQueryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, ImageFileTyptes) { FolderDepth = FolderDepth.Deep, IndexerOption = IndexerOption.UseIndexerWhenAvailable }; StorageFileQueryResult query = folder.CreateFileQueryWithOptions(ImageSearchQueryOptions); uint temp_files_count = await query.GetItemCountAsync();
UWP app won't have any problems accessing its own app directory, but UWP can't browse to another app's folders.
Thank you Junjie