Search code examples
c#google-apigoogle-drive-apigoogle-api-dotnet-clientgoogle-drive-shared-drive

search file inside shared drive By id File using the Query filter


i want to check if a folder belongs to shared drive or not . I implement this code but it return Error 400 invalid value on Query.

            var request = service.Files.List();
            var query = "id='" + driveFileId + "'";
            request.IncludeTeamDriveItems = true;
            request.SupportsTeamDrives = true;
            request.Q = query;

            request.Fields = "nextPageToken, files(id, name,parents,mimeType)";

            request.PageToken = pageToken;

            var result =request.Execute();

Solution

  • The following code will look for a folder on my drive account called kintting.

    It will then loop though all the results (there could be more then one) check the two parameters one of them should tell you if its part of team.

    var request = service.Files.List();
    request.Q = "name='knitting' and mimeType='application/vnd.google-apps.folder'";
    request.Fields = "*";
    var result = await request.ExecuteAsync();
    
    foreach (var file in result.Files)
         {
          // check file.DriveId or file.TeamDriveId
    
          }
    

    If you have the id of the folder in question. from say a previous search. you can get it directly using

     var request = service.Files.Get(fileId);
     request.Fields = "*";
     var result = await request.ExecuteAsync();