Cannot delete document programmatically

Posted by Community Admin on 04-Aug-2018 14:13

Cannot delete document programmatically

All Replies

Posted by Community Admin on 03-Jan-2012 00:00

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();

As well as:

var doc = LibrariesManager.GetManager().GetDocument(id);
LibrariesManager.GetManager().DeleteItem(doc);
LibrariesManager.GetManager().SaveChanges();

Or:

App.WorkWith().Documents().Publihed().Where(d => d.Id == id).Delete();

Nothing works.
And I can retrieve the document fine, so the "doc" or "id" variables have the right content.

This is with Sitefinity 4.3 (and we're not gonna update anytime soon).

Posted by Community Admin on 03-Jan-2012 00:00

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();

All the best,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 03-Jan-2012 00:00

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.

Posted by Community Admin on 03-Jan-2012 00:00

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,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed