public static void TrashDocument(GDocsAbstractItem item) { // Search for document(s) having exactly the title, // Delete the one with matching AlternateUri DocumentsListQuery query = new DocumentsListQuery(); query.Title = item.Name; query.TitleExact = true; DocumentsFeed docFeed = service.Query(query); DocumentEntry document = docFeed.Entries.FirstOrDefault(e => e.AlternateUri == item.URL) as DocumentEntry; if (document == null) { return; } try { document.Delete(); } catch (Exception e) { Log.Error(e.Message); Services.Notifications.Notify(GetDeleteDocumentFailedNotification()); return; } Services.Notifications.Notify(GetDocumentDeletedNotification(item.Name)); }
public void TestDeletion() { POIFSFileSystem fs = new POIFSFileSystem(); DirectoryEntry root = fs.Root; Assert.IsFalse(root.Delete()); Assert.IsTrue(root.IsEmpty); DirectoryEntry dir = fs.CreateDirectory("myDir"); Assert.IsFalse(root.IsEmpty); Assert.IsTrue(dir.IsEmpty); Assert.IsFalse(root.Delete()); // Verify can Delete empty directory Assert.IsTrue(dir.Delete()); dir = fs.CreateDirectory("NextDir"); DocumentEntry doc = dir.CreateDocument("foo", new MemoryStream(new byte[1])); Assert.IsFalse(root.IsEmpty); Assert.IsFalse(dir.IsEmpty); Assert.IsFalse(dir.Delete()); // Verify cannot Delete empty directory Assert.IsTrue(!dir.Delete()); Assert.IsTrue(doc.Delete()); Assert.IsTrue(dir.IsEmpty); // Verify now we can Delete it Assert.IsTrue(dir.Delete()); Assert.IsTrue(root.IsEmpty); fs.Close(); }
///////////////////////////////////////////////////////////////////////////// /// <summary> /// Tests word processor document creation and deletion /// </summary> [Test] public void CreateDocumentTest() { //set up a text/plain file string tempFile = Directory.GetCurrentDirectory(); tempFile = tempFile + Path.DirectorySeparatorChar + "docs_live_test.txt"; //Console.WriteLine("Creating temporary document at: " + tempFile); using (StreamWriter sw = File.CreateText(tempFile)) { sw.WriteLine("My name is Ozymandias, king of kings:"); sw.WriteLine("Look on my works, ye mighty, and despair!"); sw.Close(); } DocumentsService service = new DocumentsService(this.ApplicationName); if (this.userName != null) { service.Credentials = new GDataCredentials(this.userName, this.passWord); } service.RequestFactory = this.factory; //pick a unique document name string documentTitle = "Ozy " + Guid.NewGuid().ToString(); DocumentEntry entry = service.UploadDocument(tempFile, documentTitle); Assert.IsNotNull(entry, "Should get a valid entry back from the server."); Assert.AreEqual(documentTitle, entry.Title.Text, "Title on document should be what we provided."); Assert.IsTrue(entry.IsDocument, "What we uploaded should come back as a text document type."); Assert.IsTrue(entry.AccessControlList != null, "We should get an ACL list back"); try { Uri uri = new Uri(entry.AccessControlList); Assert.IsTrue(uri.AbsoluteUri == entry.AccessControlList); } catch (Exception e) { throw e; } entry.Update(); //try to delete the document we created entry.Delete(); //clean up the file we created File.Delete(tempFile); }
private void DeleteMenuItem_Click(object sender, EventArgs e) { if (DocList.SelectedItems.Count > 0) { DocumentEntry entry = (DocumentEntry)DocList.SelectedItems[0].Tag; DialogResult result = MessageBox.Show("Are you sure you want to delete " + entry.Title.Text + "?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { try { entry.Delete(); UpdateDocList(); } catch (Exception ex) { MessageBox.Show("Error when deleting: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
[Test] public void CreateSpreadsheetTest() { //set up a text/csv file string tempFile = Directory.GetCurrentDirectory(); tempFile = tempFile + Path.DirectorySeparatorChar + "docs_live_test.csv"; //Console.WriteLine("Creating temporary document at: " + tempFile); using (StreamWriter sw = File.CreateText(tempFile)) { sw.WriteLine("foo,bar,baz"); sw.WriteLine("1,2,3"); sw.Close(); } DocumentsService service = new DocumentsService(this.ApplicationName); if (this.userName != null) { service.Credentials = new GDataCredentials(this.userName, this.passWord); } service.RequestFactory = this.factory; //pick a unique document name string documentTitle = "Simple " + Guid.NewGuid().ToString(); DocumentEntry entry = service.UploadDocument(tempFile, documentTitle); Assert.IsNotNull(entry, "Should get a valid entry back from the server."); Assert.AreEqual(documentTitle, entry.Title.Text, "Title on document should be what we provided."); Assert.IsTrue(entry.IsSpreadsheet, "What we uploaded should come back as a spreadsheet document type."); //try to delete the document we created entry.Delete(); //clean up the file we created File.Delete(tempFile); }