More in this section
Forums / Developing with Sitefinity / Delete dynamic content item

Delete dynamic content item

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
4 posts, 1 answered
  1. Andrey
    Andrey avatar
    4 posts
    Registered:
    25 Feb 2015
    06 Oct 2015
    Link to this post

    Hi, I am trying to delete an dynamic item from code. But after this code runs my item is still on the content page in published state. Please help me, what am I doing wrong?

     

    var items = from item inthis.dynamicModuleManager.GetDataItems(this.entityType)
                where item.Status == ContentLifecycleStatus.Live && item.Visible
                select item;
    var entity= items.SingleOrDefault(el => el.GetValue<string>("Property") =="Value");
    if (entity== null)
    {
        return;
    }
    this.dynamicModuleManager.Lifecycle.Unpublish(entity);
    this.dynamicModuleManager.DeleteDataItem(entity);
    this.dynamicModuleManager.DeleteItem(entity);
    entity.SetWorkflowStatus(dynamicModuleManager.Provider.ApplicationName,                       "Deleted");
    this.dynamicModuleManager.SaveChanges();

    Best regards, Andrew 

    Answered
  2. Victor
    Victor avatar
    94 posts
    Registered:
    15 Jun 2011
    06 Oct 2015
    Link to this post

    Is the variable hotel always null?

    I don't see it assigned.  Maybe it's just exiting?

  3. Andrey
    Andrey avatar
    4 posts
    Registered:
    25 Feb 2015
    06 Oct 2015 in reply to Victor
    Link to this post

    Thanks for suggestion, Victor.

    But it has been initialized. I ran my application in debug mode, and I can see that this line of code (this.dynamicModuleManager.SaveChanges();) invoked,

  4. Velizar Bishurov
    Velizar Bishurov avatar
    143 posts
    Registered:
    18 Sep 2017
    09 Oct 2015
    Link to this post
    Hello,

    You need to work with the Master version. Please try the following code:

    var items = from item in this.dynamicModuleManager.GetDataItems(this.entityType)
                where item.Status == ContentLifecycleStatus.Master
                select item;
    var entity= items.SingleOrDefault(el => el.GetValue<string>("Property") =="Value");
    if (entity== null)
    {
        return;
    }
     
    this.dynamicModuleManager.Provider.DeleteDataItem(entity);
    this.dynamicModuleManager.SaveChanges();

    Regards,
    Velizar Bishurov
    Telerik
     
    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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
4 posts, 1 answered