Get Google.GoogleApiException 'File not found: [404]' when trying to list files in a non-root Google Drive folder


I’m trying to access files in Google Drive. I picked up code to create a Google Drive service from the Google docs

private static DriveService GetDriveService() {
  UserCredential credential;
  using (FileStream stream = new("credentials_desktop.json", FileMode.Open, FileAccess.Read)) {
    credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
      new FileDataStore("token.json", true)).Result;
  DriveService service = new(new BaseClientService.Initializer {
    HttpClientInitializer = credential,
    ApplicationName = ApplicationName,
  return service;

Using code found in this blog post, I can make a call to the Google Drive API and see all the files in the root folder…

private static void ListFiles() {
  DriveService service = GetDriveService();
  FilesResource.ListRequest fileList = service.Files.List();
  fileList.Q = "mimeType != 'application/' and 'root' in parents";
  fileList.Fields = "nextPageToken, files(id, name, size, mimeType)";
  List<File> files = new();
  string pageToken = null;
  do {
    fileList.PageToken = pageToken;
    FileList filesResult = fileList.Execute();
    IList<File> pageFiles = filesResult.Files;
    pageToken = filesResult.NextPageToken;
  } while (pageToken != null);
  // dump files to console...

That works fine, but if I try to list the files in a folder…

fileList.Q = "mimeType != 'application/' and 'Admin' in parents";

…then when it tries to make the call to fileList.Execute() I get the following exception…

File not found: . [404]
Errors [
    Message[File not found: .] Location[fileId - parameter] Reason[notFound] Domain[global]

   at Google.Apis.Requests.ClientServiceRequest`1.<ParseResponse>d__35.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Google.Apis.Requests.ClientServiceRequest`1.Execute()
   at GoogleDrivePlay.Program.ListFiles2() in d:\GoogleDrivePlay\GoogleDrivePlay\Program.cs:line 59
   at GoogleDrivePlay.Program.Main(String[] args) in d:\GoogleDrivePlay\GoogleDrivePlay\Program.cs:line 23

As you can see, the Admin folder does exist…

Anyone any idea how I can list the contents of other folders? Thanks

>Solution :

fileList.Q = "mimeType != 'application/' and 'Admin' in parents";

The issue you are having is that you are using the name of the directory ‘Admin’ you need to use the file id of the Admin directory.

Do a file.list and search for the admin directory get its file id then pass it to that instead.

fileList.Q = "name ='Admin' and mimeType != 'application/'";

Leave a Reply Cancel reply