How can I delete a document using sdk 9?
DocumentInfo document = Document.GetDocumentInfo(5, session);
document.Delete();
This method don't work
How can I delete a document using sdk 9?
DocumentInfo document = Document.GetDocumentInfo(5, session);
document.Delete();
This method don't work
Thom,
To delete a document using RA you would actually get a reference to the EntryInfo object not the DocumentInfo object. Here is a code snippet to delete an entry using RA;
Dim myRegistration As New RepositoryRegistration("localhost", "LFMAIN") Dim mySession As New Session Dim myEntry As EntryInfo mySession.LogIn("admin", "admin", myRegistration) myEntry = Entry.GetEntryInfo(94554, mySession) myEntry.Lock(LockType.Exclusive) myEntry.Delete() myEntry.Save() myEntry.Unlock() myEntry.Dispose() mySession.Close() mySession = Nothing myRegistration = Nothing
DocumentInfo.Delete works as well. In fact, DocumentInfo inherits from EntryInfo so it's really the same method. It didn't work because you didn't call DocumentInfo.Save. However, if you just want to delete a document by its ID and you don't want to query any properties on the document, then the most efficient way is to call the static method Entry.Delete. There is no need to lock a document if you are going to immediately delete it.
Michael - Makes sense. I went to the reference guide to respond to Thom's question. The 9.0 SDK documentation does not list a DocumentInfo.Delete method so I used the reference to the EntryInfo object instead.
So for completeness here is an RA code snippet that will delete a document without instantiating the DocumentInfo object;
Try Dim myRegistration As New RepositoryRegistration("localhost", "LFMAIN") Dim mySession As New Session mySession.LogIn("admin", "admin", myRegistration) 'Call the static Entry method to delete a document... 'Parameters are the entryID and the session object... Entry.Delete(94689, mySession) 'Cleanup... mySession.Close() mySession = Nothing myRegistration = Nothing Catch ex As Exception 'Display any errors... MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK) End Try