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); }
public void Delete() { FilesResource.DeleteRequest deleteRequest = DriveService.Files.Delete(SpreadsheetId); deleteRequest.SupportsAllDrives = true; deleteRequest.Execute(); }
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 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); }
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(); } }
/** * 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 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(); } }
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"); } }
static void Main(string[] args) { UserCredential credential; using (var filestream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read)) { credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(filestream).Secrets, new[] { DriveService.Scope.Drive }, "user", CancellationToken.None, new FileDataStore("DriveCommandLineSample")).Result; } // Create the service. var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Drive API Sample", }); Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File(); body.Title = "My document"; body.Description = "A test document"; body.MimeType = "text/plain"; byte[] byteArray = System.IO.File.ReadAllBytes("document.txt"); System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray); FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain"); request.Upload(); Google.Apis.Drive.v2.Data.File file = request.ResponseBody; Console.WriteLine("File id: " + file.Id); Console.WriteLine("Press Enter to end this process."); Console.ReadLine(); try { // Listing files with search. // This searches for a directory with the name DiamtoSample string Q = "title = 'My document' and mimeType = 'text/plain'"; IList <Google.Apis.Drive.v2.Data.File> _Files = DaimtoGoogleDriveHelper.GetFiles(service, Q); Q = "mimeType = 'application/vnd.google-apps.folder'"; DaimtoGoogleDriveHelper.GetFolders(service, Q); foreach (Google.Apis.Drive.v2.Data.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 Google.Apis.Drive.v2.Data.File newFile = DaimtoGoogleDriveHelper.uploadFile(service, @"c:\GoogleDriveDevelopment\dummyUploadFile.txt", directoryId); // Update The file Google.Apis.Drive.v2.Data.File UpdatedFile = DaimtoGoogleDriveHelper.updateFile(service, @"c:\GoogleDriveDevelopment\dummyUploadFile.txt", directoryId, newFile.Id); // Download the file DaimtoGoogleDriveHelper.downloadFile(service, newFile, @"C:\GoogleDriveDevelopment\downloaded.txt"); // delete The file FilesResource.DeleteRequest request1 = service.Files.Delete(newFile.Id); request1.Execute(); } // Getting a list of ALL a users Files (This could take a while.) _Files = DaimtoGoogleDriveHelper.GetFiles(service, null); foreach (Google.Apis.Drive.v2.Data.File item in _Files) { Console.WriteLine(item.Title + " " + item.MimeType); } } catch (Exception ex) { int i = 1; } Console.ReadLine(); }
public void DeleteFiles(string fileId) { FilesResource.DeleteRequest deleteRequest = service.Files.Delete(fileId); deleteRequest.Execute(); }
/// <summary> /// ファイルを削除します /// </summary> public static string DeleteFile(string fileId) { FilesResource.DeleteRequest request = OpenDrive().Files.Delete(fileId); return(request.Execute()); }
static void Main(string[] args) { // Connect with Oauth2 Ask user for permission String CLIENT_ID = "1046123799103-d0vpdthl4ms0soutcrpe036ckqn7rfpn.apps.googleusercontent.com"; String CLIENT_SECRET = "NDmluNfTgUk6wgmy7cFo64RV"; DriveService service = Authentication.AuthenticateOauth(CLIENT_ID, CLIENT_SECRET, Environment.UserName); // connect with a Service Account //string ServiceAccountEmail = "*****@*****.**"; //string serviceAccountkeyFile = @"C:\GoogleDevelop\Diamto Test Everything Project-78049f608668.p12"; //DriveService service = Authentication.AuthenticateServiceAccount(ServiceAccountEmail, serviceAccountkeyFile); if (service == null) { Console.WriteLine("Authentication error"); Console.ReadLine(); } try { // 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:\GoogleDevelop\dummyUploadFile.txt", directoryId); // Update The file File UpdatedFile = DaimtoGoogleDriveHelper.updateFile(service, @"c:\GoogleDevelop\dummyUploadFile.txt", directoryId, newFile.Id); // Download the file DaimtoGoogleDriveHelper.downloadFile(service, newFile, @"C:\GoogleDevelop\downloaded.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 = DaimtoGoogleDriveHelper.GetFiles(service, null); foreach (File item in _Files) { Console.WriteLine(item.Title + " " + item.MimeType); } } catch (Exception ex) { int i = 1; } Console.ReadLine(); }
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); } }
/// <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 static bool DeleteObject(DriveService service, string objectId) { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(objectId); DeleteRequest.Execute(); return(true); }
private static void DeleteFile(DriveService driveService, DriveFile targetFile) { FilesResource.DeleteRequest deleteRequest = driveService.Files.Delete(targetFile.Id); deleteRequest.SupportsAllDrives = true; _ = deleteRequest.Execute(); }
internal static void DeleteFile(DriveService service, string fileId) { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(fileId); DeleteRequest.Execute(); }
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(); }
public void DeleteGoogleFile(string fileId) { FilesResource.DeleteRequest DeleteRequest = service.Files.Delete(fileId); DeleteRequest.Execute(); }