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(); //https://stackoverflow.com/questions/49534842/createquerywithoptions-causes-system-interop-com-exception
qOption.ApplicationSearchFilter = $"System.FileName:{folderNameSearchKeyword}"; //https://docs.microsoft.com/en-us/windows/win32/search/-search-3x-advancedquerysyntax?redirectedfrom=MSDN
//qOption.UserSearchFilter
qOption.FolderDepth = FolderDepth.Shallow;
switch (await parentFolder.GetIndexedStateAsync())
{
case (IndexedState.FullyIndexed):
qOption.IndexerOption = IndexerOption.OnlyUseIndexerAndOptimizeForIndexedProperties;
break;
default:
qOption.IndexerOption = IndexerOption.UseIndexerWhenAvailable;
break;
}
SortEntry sort = new SortEntry()
{
PropertyName = "System.FileName",
AscendingOrder = true
};
qOption.SortOrder.Add(sort);
if (!parentFolder.AreQueryOptionsSupported(qOption))
{
qOption.SortOrder.Clear();
}
try
{
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*"
throw;
}
}
xs
