/// <summary> /// Creates a new file. /// Documentation https://developers.google.com/drive/v3/reference/files/create /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Drive service.</param> /// <param name="body">A valid Drive v3 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>FileResponse</returns> public async Task <File> Create(File body, FilesCreateOptionalParms optional = null) { try { var googleIdObject = await GenerateId(); // Initial validation. if (_service == null) { throw new ArgumentNullException("service"); } else if (body == null) { throw new ArgumentNullException("body"); } else if (googleIdObject == null) { throw new ArgumentNullException("id value is null"); } // Building the initial request. body.Id = googleIdObject.Ids[0]; var request = _service.Files.Create(body); // Applying optional parameters to the request. request = (FilesResource.CreateRequest)GoogleDriveFunctionsHelper.ApplyOptionalParms(request, optional); // Requesting data. return(await request.ExecuteAsync()); } catch (Exception ex) { throw new Exception("Request Files.Create failed.", ex); } }
/// <summary> /// Creates a new file. /// Documentation https://developers.google.com/drive/v3/reference/files/create /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated drive service.</param> /// <param name="body">A valid drive v3 body.</param> /// <param name="optional">Optional paramaters.</param> /// <returns>FileResponse</returns> public static File Create(driveService service, File body, FilesCreateOptionalParms optional = null) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Building the initial request. var request = service.Files.Create(body); // Applying optional parameters to the request. request = (FilesResource.CreateRequest)SampleHelpers.ApplyOptionalParms(request, optional); // Requesting data. return(request.Execute()); } catch (Exception ex) { throw new Exception("Request Files.Create failed.", ex); } }