Cannot delete document programmatically
Hi,
I can't manage to delete a document programmatically. I get no exception, it just does nothing.
I tried many different things, including:
var doc = LibrariesManager.GetManager().GetDocument(id);
LibrariesManager.GetManager().DeleteDocument(doc);
LibrariesManager.GetManager().SaveChanges();
var doc = LibrariesManager.GetManager().GetDocument(id);
LibrariesManager.GetManager().DeleteItem(doc);
LibrariesManager.GetManager().SaveChanges();
App.WorkWith().Documents().Publihed().Where(d => d.Id == id).Delete();
Hi Thomas,
The first bit of code is incorrect - you get a new manager for every call, which is not right. You need to get a single instance of a manager and operate only with it. So the code should be:
var manager = LibrariesManager.GetManager();
var doc = manager.GetDocument(id);
manager.DeleteDocument(doc);
manager.SaveChanges();
Hi Lubomir,
Actually, that's already what I do in my code. I changed it here because I thought that would simplify things, removing one line. I assumed it'd be the same instance every time.
So yeah, that's not the issue.
Hi Thomas,
I uploaded one document and tried the following code and it deleted it. Are you sure the "id" parameter that you pass to GetDocument is valid? It must the "id" of the Live version of the document.
Regards,