0
votes

i have a question regrading Google Drive API and editing my uploaded files. I have uploaded na excel file to google drive with a service account in Asp.Net Core C# and shared it with my private google account. Here is my code:

FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, _GetDriveMimeType(fileToUpload));

var progress = request.Upload();

File file = request.ResponseBody;

Permission newPermission = new Permission();
newPermission.EmailAddress = "[email protected]";
newPermission.Value = "[email protected]";
newPermission.Type = "user";
newPermission.Role = "writer";

PermissionsResource.InsertRequest insertRequest = service.Permissions.Insert(newPermission, file.Id);
insertRequest.SendNotificationEmails = false;
insertRequest.Execute();

return file;

When i open the file with the "AlternateLink" which i get from the file, and i am editing the file with my private google account, i want that the changes are synced back to the original shared document.

In my case it is saving the changes to a new file in the "My drive" section and didn't sync it back to the base file.

Can anyone help me please?

Regards, Andreas

1
I think you need to share the file with the user if you want them to be able to edit directly the original file. - DaImTo
I already shared the file with my private gmail address - see Permission in my code, or do you mean anything else? - Andreas

1 Answers

0
votes

I had to convert the uploaded file to a google doc and afterwards i was able to edit and save it back to the original.

You must set the "convert" variable to true.

Here is the code:

 FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, _GetDriveMimeType(fileToUpload));

 request.Convert = true;