pointbraker
pointbraker

Reputation: 51

How to upload a file to an specific folder in Google drive using C#

I have a Folder ID and a file that I should upload into that gDrive Folder. I have tried the following:

File body = new File();
body.Title = titulo; // titulo is a string that contains the tittle of the file
body.Description = descripcion; // the description, it is a string as well
body.MimeType = setMimetype(rutaArchivo); // and this is a method that sets the mimetype according to the file extension.`

I try to use body.Parents but I have had no luck, body.parents.add does not receive only a string (I have tried to give the string containing the gdrive folder id) and I don't really understand the documentation on parents.Insert.

Upvotes: 2

Views: 2167

Answers (1)

Ali Afshar
Ali Afshar

Reputation: 41643

You should add a parent reference (you were very close):

body.Parents = new List<ParentReference>()
      {new ParentReference() {Id = parentId}};

Where parentId is the string file ID of the parent.

Upvotes: 3

Related Questions