Attached is a list of scripts we use in our webAPIs for managing files on Google Drive
Rename a File or Folder
var name = "some name"; //whatever you want to change the name to var fileId = "OISDEF89SWE9023J2309D8DF"; //the ID of the folder or file you're renaming Google.Apis.Drive.v3.Data.File file = new Google.Apis.Drive.v3.Data.File() { Name = name }; var updateRequest = service.Files.Update(file, fileId); updateRequest.Fields = "name"; file = updateRequest.Execute();
So, here’s the deal: You make a new “File”. It’s just a class object that you’re creating, and all the google file properties are there. It’s about as basic as you can get when you think about it!
Once you make the object, you set the value of the field you want to change, which is simply the name of the file.
Now, you make a “request”, which is kind of like formulating a command from the service. You’re saying, here’s the fileID I want to modify and here’s a container that has the changes I want.
Then, you add the fields you want to modify, in this case, just the name. If it was a bunch, you just send a comma delimited string. That tells it, ok, here’s a class object with 1000 properties. Go to the “name” property and change it to what is contained in the update request. That way, you don’t need to tell Google to update the entire thing, just the ones you want.
So, it’s a simple solution, but honestly, it took me HOURS to figure it out because it’s just not listed anywhere!
I’m going to start putting in a list of other scripts we use as this system grows (if only for our own reference!)
Finding subfolders:
var q = string.Format("mimeType = 'application/vnd.google-apps.folder' and '{0}' in parents", SomeFolderGoogleID);
Here’s HUGE heads-up. If you do it this way:
var q = string.Format("mimeType = 'application/vnd.google-apps.folder' and parents in '{0}'", OfficeJobFolderID);
That works, and for SQL nerds like me, that makes sense BUT IT IS WRONG. Here’s the problem. We sometimes put a folder under multiple parents. If you do a query with “parents in XYZ”, it will show you the folders within that parent, but NOT the folders with that parent AND folder ABC. However, if you say “XYZ in parents”, it works fine. (that was 4 hours of my life right there!)