0

C# アプリ

ファイル ID を使用して、Gdrive で共有されているファイルを更新する必要があります。

コード:

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;
        }

スローされたエラー:ファイルが見つかりません

4

1 に答える 1