public void Delete() { FilesResource.DeleteRequest deleteRequest = DriveService.Files.Delete(SpreadsheetId); deleteRequest.SupportsAllDrives = true; deleteRequest.Execute(); }
public void DeleteFile(string fileId) { CreateApiService createApiService = new CreateApiService(); FilesResource.DeleteRequest request = createApiService.CallAppiService().Files.Delete(fileId); request.Execute(); }
public static string DeleteFile(string localFilePath, string gFileId) { IsDeletingFile = true; string deleteResult = ""; if (string.IsNullOrWhiteSpace(gFileId)) { deleteResult = "gFileId is null or empty!"; return(deleteResult); } DriveService service = GetGDriveService(); try { FilesResource.DeleteRequest deleteRequest = service.Files.Delete(gFileId); deleteResult = deleteRequest.Execute(); } catch (Exception e) { Debug.WriteLine("An error occurred: " + e.Message); throw new Exception($"{localFilePath} could not be deleted from GDrive (Id: {gFileId})", e); } finally { IsDeletingFile = false; } service?.Dispose(); return(deleteResult); }
private bool DeleteFilesInFolder(Google.Apis.Drive.v2.Data.File Folder) { bool Succes = false; try { FilesResource.ListRequest myList = m_Drive.Files.List(); myList.Q = string.Format("trashed = false and '{0}' in parents", Folder.Id); Google.Apis.Drive.v2.Data.FileList myFiles = myList.Fetch(); foreach (Google.Apis.Drive.v2.Data.File myFile in myFiles.Items) { FilesResource.DeleteRequest myDelRequest = m_Drive.Files.Delete(myFile.Id); myDelRequest.Fetch(); } Succes = true; } catch (Exception ex) { ErrorDump.AddError(System.IntPtr.Zero, "DriveSync.cs", "DeleteFilesInFolder", ex); if (FinishedEvent != null) { FinishedEvent(new DriveFinishedEventArgs(false, "Fout bij verwijderen oude database", ex)); } } return(Succes); }
public async Task <string> DeleteAsync(string fileId) { FilesResource.DeleteRequest deleteRequest = _driveService.Files.Delete(fileId); var deleteResponse = await deleteRequest.ExecuteAsync(); return(deleteResponse); }
public static GoogleDriveBaseResult DeleteResource(Connection connection, string fileOrFolderId) { CheckConnectionOrException(connection); FilesResource.DeleteRequest request = connection.Service.Files.Delete(fileOrFolderId); GoogleDriveBaseResult result = ExecuteRequest <FilesResource.DeleteRequest, string, GoogleDriveBaseResult>(request, null); return(result); }
private void button2_Click(object sender, EventArgs e) { if ( MessageBox.Show( "Confirm deleting of shown files from trash?", "", MessageBoxButtons.YesNo ) != DialogResult.Yes ) { return; } stat.Text = "Deleting"; int c = 0; foreach (DataRow r in table.Rows) { c++; l3.Text = c + "/" + table.Rows.Count; Application.DoEvents(); /* * // the paranoid's check, tested OK with about 10000 files * FilesResource.GetRequest prequest = service.Files.Get(r["id"].ToString()); * prequest.Fields = "labels/trashed"; * File file = prequest.Execute(); * if (!(bool) file.Labels.Trashed) * MessageBox.Show("Not Trashed!"); */ FilesResource.DeleteRequest request = service.Files.Delete(r["id"].ToString()); // sometime happens that google server replays with errors like // 500 - Internal server error // I'm assuming this is transient and recoverable, so retrying 4 more times before giving up // going beyond that probably means a service outage and google drive wouldn't work anyway for (int i = 0; i < 5; i++) { try { request.Execute(); break; } catch (Exception ex) { if (i == 4) { throw(ex); } Thread.Sleep(1000); } } } table.Rows.Clear(); stat.Text = ""; button2.Enabled = false; MessageBox.Show("Done deleting"); }
private async Task RemoveExistingFile(DriveService service, string fileIdToDelete) { mLogger.LogDebug($"Going to remove file id {fileIdToDelete} from {mTaskerDriveDirectory} directory"); FilesResource.DeleteRequest deleteRequest = service.Files.Delete(fileIdToDelete); deleteRequest.Fields = "id"; string deleteResult = await deleteRequest.ExecuteAsync().ConfigureAwait(false); mLogger.LogDebug($"Done removing file id {fileIdToDelete}. Delete result: {deleteResult}"); }
// Removes existing spreadsheet asynchronously. internal static async Task RemoveSpreadsheetAsync(this DriveService driveService, string spreadsheetId) { // Await for google apis request quota availability. await SessionRequestsLimiter.Instance.WaitAsync(); // Get appropriate request instance FilesResource.DeleteRequest removeSpreadsheetRequest = GoogleServicesExtensionsRequestsFactory.GetRemoveSpreadsheetRequest(driveService, spreadsheetId); // Await execution results of the removeSpreadsheetRequest in safe, asynchronous manner. await RequestsExecutor.SafeExecuteAsync(removeSpreadsheetRequest); }
// Removes existing spreadsheet. internal static void RemoveSpreadsheetSync(this DriveService driveService, string spreadsheetId) { // Wait for google apis request quota availability. SessionRequestsLimiter.Instance.Wait(); // Get appropriate request instance FilesResource.DeleteRequest removeSpreadsheetRequest = GoogleServicesExtensionsRequestsFactory.GetRemoveSpreadsheetRequest(driveService, spreadsheetId); // Execute removeSpreadsheetRequest in safe, synchronous manner. RequestsExecutor.SafeExecuteSync(removeSpreadsheetRequest); }
private void deleteFile(DriveService service, Google.Apis.Drive.v3.Data.File file) { UpdateSubProgressBar(0); UpdateSubStatusLabel("Deleting: " + file.Name); FilesResource.DeleteRequest delReq = service.Files.Delete(file.Id); delReq.Execute(); UpdateSubProgressBar(subProgressBar.Maximum); UpdateSubStatusLabel("Deleted: " + file.Name); Thread.Sleep(25); }
/// <summary> /// Realiza a exclusão de um item a partir do seu nome. /// </summary> /// <param name="tipo">Tipo do item (pasta ou arquivo).</param> /// <param name="nome">Nome do arquivo.</param> /// <param name="idPastaPai">ID da pasta onde o arquivo está armazenado.</param> public async Task ExcluirPorNome(TipoGoogleDriveFile tipo, string nome, string idPastaPai = null) { var file = await ProcurarPorNome(tipo, nome, idPastaPai); if (file == null) { return; } FilesResource.DeleteRequest deleteRequest = _driveService.Files.Delete(file.Id); await deleteRequest.ExecuteAsync(); }
public static void DeleteGoogleFileByName(string filesName) { var fileIds = (from file in GetDriveFiles() where file.Name == (filesName) select file.Id).ToList(); DriveService service = GetService(); foreach (var fileId in fileIds) { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(fileId); DeleteRequest.Execute(); } }
public void deleteAllFiles(string filesName) { var fileIds = (from file in this.GetDriveFiles() where file.Name == (filesName + Path.GetExtension(file.Name)) select file.Id).ToList(); DriveService service = GetService(); foreach (var fileId in fileIds) { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(fileId); DeleteRequest.Execute(); } }
public async Task <bool> DeleteFile(string name) { try { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(name); await DeleteRequest.ExecuteAsync(); return(true); } catch (Exception) { return(false); } }
/** * Permanently delete a file, skipping the trash. * * @param fileId ID of the file to delete. */ public void deleteFile(string fileName) { string fileId = (from file in this.GetDriveFiles() where @"/images/" + file.Name == (fileName + Path.GetExtension(file.Name)) select file.Id).FirstOrDefault(); if (fileId != null) { //create service DriveService service = GetService(); FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(fileId); DeleteRequest.Execute(); } }
///Deletes the file permanently private static string DeleteFilePermanently(DriveService service, File _file) { string Resp = null; try { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(_file.Id); Resp = DeleteRequest.Execute(); } catch (Exception ex) { throw ex; } return(Resp); }
public GoogleDriveManagerResult DeleteFile(DriveService service, string fileId) { result = new GoogleDriveManagerResult(); try { FilesResource.DeleteRequest request = service.Files.Delete(fileId); result.GoogleDriveStatus = request.Execute(); return(result); } catch (Exception e) { result.Exceptions.Add(e); WriteToConsole(GoogleDriveManagementConstants.DeleteFileException + e.Message); return(result); } }
public bool DeleteFiles(string name) { string Q_doc = "title = '" + name + "' and mimeType = 'application/vnd.google-apps.document'"; IList <File> _Files = GoogleRepository.GetFiles(service, Q_doc); if (_Files.Count != 0) { FilesResource.DeleteRequest request = service.Files.Delete(_Files[0].Id); request.Execute(); return(true); } else { return(false); } }
public static Task <bool> Delete(string id) { return(Task.Run(() => { bool success = false; try { FilesResource.DeleteRequest deleteRequest = Service.Files.Delete(id); success = deleteRequest.Execute() == ""; } catch (Exception ex) { Console.WriteLine(ex.Message); } return success; })); }
public static Task <string> DeleteFileAsync(string gFileId) { IsDeletingFile = true; Task <string> deleteTask = null; DriveService service = GetGDriveService(); try { FilesResource.DeleteRequest deleteRequest = service.Files.Delete(gFileId); deleteTask = deleteRequest.ExecuteAsync(); } catch (Exception e) { Debug.WriteLine("An error occurred: " + e.Message); throw; } finally { IsDeletingFile = false; } service?.Dispose(); return(deleteTask); }
public override void DeleteFile(File file) { if (!file.Parent.Equals(this)) { throw new ArgumentException("The specified directory could not be found"); } GoogleDriveFile googleDriveFile = file as GoogleDriveFile; if (storage.UseTrash) { FilesResource.TrashRequest request = storage.Service.Files.Trash(googleDriveFile.file.Id); request.Execute(); } else { FilesResource.DeleteRequest request = storage.Service.Files.Delete(googleDriveFile.file.Id); request.Execute(); } }
public void DeleteFile(string FilePath) { Google.Apis.Drive.v2.Data.File File = GetFileByPath(FilePath); if (File != null) { if (!File.MimeType.Equals("application/vnd.google-apps.folder")) { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(File.Id); DeleteRequest.Execute(); } else { throw new Exception("Cannot currently delete a folder"); } } else { throw new Exception("File not found"); } }
public override void DeleteDirectory(Directory directory) { if (!directory.Parent.Equals(this)) { throw new ArgumentException("The specified directory could not be found"); } GoogleDriveDirectory googleDriveDirectory = directory as GoogleDriveDirectory; if (storage.UseTrash) { FilesResource.TrashRequest request = storage.Service.Files.Trash(googleDriveDirectory.folder.Id); request.Execute(); } else { FilesResource.DeleteRequest request = storage.Service.Files.Delete(googleDriveDirectory.folder.Id); request.Execute(); } }
/// <summary> /// Realiza a exclusão de um item a partir do seu ID. /// </summary> /// <param name="id">ID do arquivo que será excluído.</param> public async Task ExcluirPorId(string id) { FilesResource.DeleteRequest deleteRequest = _driveService.Files.Delete(id); await deleteRequest.ExecuteAsync(); }
static void Main(string[] args) { //Google Drive scopes Documentation: https://developers.google.com/drive/web/scopes string[] scopes = new string[] { DriveService.Scope.Drive, // view and manage your files and documents DriveService.Scope.DriveAppdata, // view and manage its own configuration data DriveService.Scope.DriveAppsReadonly, // view your drive apps DriveService.Scope.DriveFile, // view and manage files created by this app DriveService.Scope.DriveMetadataReadonly, // view metadata for files DriveService.Scope.DriveReadonly, // view files and documents on your drive DriveService.Scope.DriveScripts }; // modify your app scripts DriveService service = GDriveAccount.Authenticate("*****@*****.**", "Columbia State-99db1bd2a00e.json", scopes); if (service == null) { Console.WriteLine("Authentication error"); Console.ReadLine(); } DriveDir(service, "0Byi5ne7d961QVS1XOGlPaTRKc28"); try { ChildrenResource.ListRequest request1 = service.Children.List("0Byi5ne7d961QVS1XOGlPaTRKc28"); int j = 1; request1.MaxResults = 1000; List <string> folders = new List <string>(); List <string> files = new List <string>(); do { try { ChildList children = request1.Execute(); foreach (ChildReference child in children.Items) { //Console.WriteLine("{0} File Id: {1}", j, child.Id); File file = service.Files.Get(child.Id).Execute(); if (file.MimeType == "application/vnd.google-apps.folder") { folders.Add(file.Title); } else { files.Add(file.Title); } //Console.WriteLine("Title: {0} - MIME type: {1}", file.Title, file.MimeType); //Console.WriteLine(); //j++; } request1.PageToken = children.NextPageToken; } catch (Exception e) { Console.WriteLine("An error occurred: " + e.Message); request1.PageToken = null; } } while (!String.IsNullOrEmpty(request1.PageToken)); foreach (string dir in folders) { Console.WriteLine(dir); } // Listing files with search. // This searches for a directory with the name DiamtoSample string Q = "title = 'Files' and mimeType = 'application/vnd.google-apps.folder'"; //string Q = "mimeType = 'application/vnd.google-apps.folder'"; IList <File> _Files = GoogleDrive.GetFiles(service, null); foreach (File item in _Files) { Console.WriteLine(item.Title + " " + item.MimeType); } // If there isn't a directory with this name lets create one. if (_Files.Count == 0) { _Files.Add(GoogleDrive.createDirectory(service, "Files1", "Files1", "root")); } // We should have a directory now because we either had it to begin with or we just created one. if (_Files.Count != 0) { // This is the ID of the directory string directoryId = _Files[0].Id; //Upload a file //File newFile = DaimtoGoogleDriveHelper.uploadFile(service, @"c:\GoogleDevelop\dummyUploadFile.txt", directoryId); File newFile = GoogleDrive.uploadFile(service, @"c:\Games\gtasamp.md5", directoryId); // Update The file //File UpdatedFile = DaimtoGoogleDriveHelper.updateFile(service, @"c:\GoogleDevelop\dummyUploadFile.txt", directoryId, newFile.Id); File UpdatedFile = GoogleDrive.updateFile(service, @"c:\Games\gtasamp.md5", directoryId, newFile.Id); // Download the file GoogleDrive.downloadFile(service, newFile, @"C:\Games\download.txt"); // delete The file FilesResource.DeleteRequest request = service.Files.Delete(newFile.Id); request.Execute(); } // Getting a list of ALL a users Files (This could take a while.) _Files = GoogleDrive.GetFiles(service, null); foreach (File item in _Files) { Console.WriteLine(item.Title + " " + item.MimeType); } } catch (Exception ex) { int i = 1; } Console.ReadLine(); }
internal static void DeleteFile(DriveService service, string fileId) { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(fileId); DeleteRequest.Execute(); }
private static void DeleteFile(DriveService driveService, DriveFile targetFile) { FilesResource.DeleteRequest deleteRequest = driveService.Files.Delete(targetFile.Id); deleteRequest.SupportsAllDrives = true; _ = deleteRequest.Execute(); }
/// <summary> /// Delete method. /// </summary> /// <param name="id">The id of the item to delete.</param> public void Delete(string id) { FilesResource.DeleteRequest request = driveService.Files.Delete(id); request.Execute(); }
public async Task<String> TryRemoveRecordFromGoogleDrive(FileEntityAggregator targetFile) { DriveService driveService = await TryGetAuthorizer(); FilesResource.DeleteRequest deleteRequest = new FilesResource.DeleteRequest( driveService, targetFile.GoogleDriveParentId); return await deleteRequest.ExecuteAsync(); }
static void Main(string[] args) { String CLIENT_ID = "1046123799103-7mk8g2iok1dv9fphok8v2kv82hiqb0q6.apps.googleusercontent.com"; String CLIENT_SECRET = "GeE-cD7PtraV0LqyoxqPnOpv"; string[] scopes = new string[] { DriveService.Scope.Drive, DriveService.Scope.DriveFile}; // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData% UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = CLIENT_ID, ClientSecret = CLIENT_SECRET } , scopes , Environment.UserName , CancellationToken.None , new FileDataStore("Daimto.GoogleDrive.Auth.Store")).Result; DriveService service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Drive API Sample", }); // Things to search on. // Listing files with search. // This searches for a directory with the name DiamtoSample string Q = "title = 'DiamtoSample' and mimeType = 'application/vnd.google-apps.folder'"; IList<File> _Files = DaimtoGoogleDriveHelper.GetFiles(service, Q); foreach (File item in _Files) { Console.WriteLine(item.Title + " " + item.MimeType); } // If there isn't a directory with this name lets create one. if (_Files.Count == 0) { _Files.Add(DaimtoGoogleDriveHelper.createDirectory(service, "DiamtoSample", "DiamtoSample", "root")); } // We should have a directory now because we either had it to begin with or we just created one. if (_Files.Count != 0) { // This is the ID of the directory string directoryId = _Files[0].Id; //Upload a file File newFile = DaimtoGoogleDriveHelper.uploadFile(service,@"c:\temp\hold.txt",directoryId); // Update The file File UpdatedFile = DaimtoGoogleDriveHelper.updateFile(service, @"c:\temp\hold.txt", directoryId, newFile.Id); // Download the file DaimtoGoogleDriveHelper.downloadFile(service, newFile, @"C:\" + newFile.Title); // delete The file FilesResource.DeleteRequest request = service.Files.Delete(newFile.Id); request.Execute(); } // Getting a list of ALL a users Files (This could take a while.) _Files = DaimtoGoogleDriveHelper.GetFiles(service, null); foreach (File item in _Files) { Console.WriteLine(item.Title + " " + item.MimeType); } }