[UWP] Item Count Exception

kranthi kumar 206 Reputation points

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, issue

not sure what is the issue with my code, any clue ?

Universal Windows Platform (UWP)
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,177 questions
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
760 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 47,471 Reputation points

    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.

  2. Junjie Zhu - MSFT 14,136 Reputation points Microsoft Vendor

    Hi @kranthi kumar

    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

    0 comments No comments