Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • anthony hall 222 posts 536 karma points
    Apr 14, 2010 @ 13:29
    anthony hall
    0

    best way to delete node programmatically

    Umbraco 4.03

    i have some code that read's xml finds the related date and then deletes the node and re-import the updated content. 

    I'm getting the following log. which leads me to believe i'm not deleting the node completely and i need to update the sitemap

    Error adding to SiteMapProvider: System.InvalidOperationException: Multiple nodes with the same URL '/telly/schedule/2010/01/23/myshow' were found. XmlSiteMapProvider requires that sitemap nodes have unique URLs.     at System.Web.StaticSiteMapProvider.AddNode(SiteMapNode node, SiteMapNode parentNode)     at umbraco.presentation.nodeFactory.UmbracoSiteMapProvider.loadNodes(String parentId, SiteMapNode parentNode)

    i can't help thinking some of my code is overkill. I'm looping through quite a bit of content, so i need to trim the fat on this. 

     

    oldDoc.UnPublish();
    oldDoc.delete();
    oldDoc.Save(); // is this necessary
    umbraco.library.RefreshContent();
    umbraco.library.UpdateDocumentCache(parentDocId);
    

     

    Also any tips on the most efficient way to import from xml. ie do you publish within the foreach of do you publish at the end of the operation. I'm getting really inconsistent results. I have something like the following

     

                foreach (var show in showSchedules)
                {
                        var currentPage = Document.MakeNew(show.EventTitle, dt, author, parentNodeId); currentPage.getProperty("eventDisplayDate").Value = GetEventDisplay(show.EventStartDate); currentPage.getProperty("eventDate").Value = show.EventDate; currentPage.getProperty("title").Value = show.EventTitle;
                        currentPage.getProperty("teaser").Value = show.EventSynopsis;
                        currentPage.getProperty("eventId").Value = show.EventId;
                        currentPage.Save();
                        currentPage.Publish(currentPage.User);
                        umbraco.library.UpdateDocumentCache(currentPage.Id);
                }
    
        umbraco.library.UpdateDocumentCache(parent.Id);
            parent.PublishWithSubs(author);
    

     

     

     

     

     

     

     

     

     

     

Please Sign in or register to post replies

Write your reply to:

Draft