SmilingMoon avatar image
0 Votes"
SmilingMoon asked SmilingMoon commented

How to create QueryOptions to search subfolders starts with "2016-06*" in UWP app?

I want to search sub folders starts with "2016-06" under parentFolder.
So, I set ApplicationSearchFilter = "System.FileName:2016-06*"
But, parentFolder.CreateFolderQueryWithOptions(qOption); throws "Error HRESULT E_FAIL has been returned from a call to a COM component." the parentFolder.path is"C:\Users\tester\Pictures\Test Result\2020\2016"

But strangely, sometimes it work when search "System.FileName:2016*" against its parent folder ""C:\Users\tester\Pictures\Test Result\2020".
It seems I'm using QueryOptions not properly for CreateFolderQueryWithOptions. What did I do wrong?

 async public static Task<StorageFolderQueryResult> GetSubFolders_MatchingName(StorageFolder parentFolder, string folderNameSearchKeyword)
             QueryOptions qOption = new QueryOptions(); //
             qOption.ApplicationSearchFilter = $"System.FileName:{folderNameSearchKeyword}"; //
             qOption.FolderDepth = FolderDepth.Shallow;
             switch (await parentFolder.GetIndexedStateAsync())
                 case (IndexedState.FullyIndexed):
                     qOption.IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties;
                     qOption.IndexerOption = IndexerOption.UseIndexerWhenAvailable;
             SortEntry sort = new SortEntry()
                 PropertyName = "System.FileName",
                 AscendingOrder = true
             if (!parentFolder.AreQueryOptionsSupported(qOption))
                 StorageFolderQueryResult queryResult = parentFolder.CreateFolderQueryWithOptions(qOption);
                 return queryResult;

             catch(Exception ex)
                => Fails: ParentFolder=C:\Users\tester\Pictures\Test Result\2020\2016, and ApplicationSearchFilter="System.FileName:2016-06*"


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I tried to test your code. I created a new folder named Test under Picture library, then I created a folder named 2020 under the Test folder, created a folder named 2016 under the 2020 folder. After that, I created some folders named with the prefix "2016-16".

I set the "C:\Users\username\Pictures\Test\2020\2016" folder and "2016-06*" as parameters for the GetSubFolders_MatchingName method. And it could get all the subfolders with the prefix `2016-16' under the 2016 folder without any issue.

Like this:


What is the error code you got when you running your app?

0 Votes 0 ·
tempsnip.png (16.8 KiB)

I couldn't find the error code. I changed the logic totally to avoid the situation and cannot duplicate it now. Thank you so much for help.

0 Votes 0 ·

0 Answers