user3783265
user3783265

Reputation: 23

Determine if the folder Id is a shared drive folder or a simple drive folder

Is there a way to determine if the folder is shared Drive folder or not with Google Drive API?

Following is the code I am using to check this:

DriveService service = GetService();
var request = service.Files.List();
request.IncludeTeamDriveItems = true;
request.SupportsTeamDrives = true;
IList<File> listFiles = request.Execute().Files;

if (listFiles != null && listFiles.Count > 0)
{
   foreach (var file in listFiles)
   {
       if(file.TeamDriveId == aIdFolder)
       {
          //Yes It's a shared drive folder
       }
   }
}

Please advise.

Upvotes: 1

Views: 274

Answers (2)

ba7russ
ba7russ

Reputation: 68

Proposed solution works for me:

        var listFiles = ListAllFiles(service).Files;

        if (listFiles != null && listFiles.Count > 0)
        {
            foreach (var file in listFiles)
            {
                if (file.Id == aIdFolder && !String.IsNullOrWhiteSpace(file.TeamDriveId))
                {
                     //here your result
                    return true;

                }
            }
        }

Upvotes: -1

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116968

If you check the file response.

check the driveid property

enter image description here

I suspect that it would be the same if its a directory thats on a shared drive. I dont have access to a drive now. Let me know if it doesnt work.

Upvotes: 2

Related Questions