Problems with FileQuery in Window 11

Markus Schertler 41 Reputation points
2021-10-26T06:01:08.13+00:00

Is it possible that UWP has problems with files in Windows 11? The code below finds the .Xml files in the folder for some time than it comes that it do not find the file anymore. But there are one ore more files. When i restart the computer the file is found.

//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
public static async Task Entry_Data_Change_Request_Process(string P_Caller_N)
//'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
{
  Exception p_ex = null;

  bool Do_Data_Change = true;

  StorageFolder app_Folder_Data_Change_Request_p;
  Entry_Data_Change_FileInfo entry_Data_Change_FileInfo_p = null;

  StorageFile item_1 = null;

  try
  {
    app_Folder_Data_Change_Request_p =
    AppGlobals.AppGlobals.App_Folder_Data_Change_Request;

    string item_before_name = "";

    // Set options for file type and sort order.
    fileTypeFilter = new List<string>();
    fileTypeFilter.Add(".Xml");
    queryOptions = new QueryOptions(CommonFileQuery.OrderByName, fileTypeFilter);

    int Data_Access_Prog_Time_Last_Loop_Count_For_Write_File = 0;

    while (true)
    {
      Data_Access_Prog_Time_Last_Loop_Count_For_Write_File++;

      // Offen: Das Holen in extra Prozedur.
      results = app_Folder_Data_Change_Request_p.
                CreateFileQueryWithOptions(queryOptions);

      sortedFiles = await results.GetFilesAsync();

      if (sortedFiles.Count() == 0)
      {
Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Joe Andreshak 1 Reputation point Microsoft Employee
    2021-11-11T22:19:37.877+00:00

    [In case it helps someone else ...]
    I had essentially the same problem (yesterday), where GetFilesAsync() didn't return the files with Windows 11 after an upgrade from Windows 10. After some work, I realized the following. If I changed the QueryOptions to not use the indexer, then it worked:

                queryOptions.IndexerOption = IndexerOption.DoNotUseIndexer;
    

    ... which led me to question Windows 11 indexing. It turns out I had less than 30GB left on my main drive, for which case I read somewhere Windows 10/11 doesn't index. Freeing up the storage from the install got the indexer working, and then I was able to query the files anywhere using the indexer.