How update file shared in Gdrive

92 views
Skip to first unread message

ram suresh.r

unread,
Oct 17, 2013, 1:37:11 AM10/17/13
to google-api-d...@googlegroups.com
Hi all

i have C# app i need to update a file that is shared ,i am using below using below code

public static Google.Apis.Drive.v2.Data.File UpdateFile(DriveService service, String fileId, String newTitle,
String newDescription, String newMimeType, String newFilename, bool newRevision)
{
try
{
// First, retrieve the file from the Google Drive.
Google.Apis.Drive.v2.Data.File file = service.Files.Get(fileId).Fetch();

// Set the file's new metadata.
file.Title = newTitle;
// file.Description = newDescription;
file.MimeType = newMimeType;

// Get the file's new content and read it into a memory stream
byte[] byteArray = System.IO.File.ReadAllBytes(newFilename);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

// Call the Update API method passing in the updated information.
FilesResource.UpdateMediaUpload request = service.Files.Update(file, fileId, stream, newMimeType);
// Tell Google Drive if this is a new revision of the file or not.
request.NewRevision = newRevision;
// Execute the update
request.Upload();

// Get the response back from Google Drive and set the updatedFile object to the returned File informational object
Google.Apis.Drive.v2.Data.File updatedFile = request.ResponseBody;
// Return the updated file object so the caller has a handle on it.
return updatedFile;
}

Reply all
Reply to author
Forward
0 new messages