Copied to clipboard

Flag this post as spam?

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


  • ReneRam 21 posts 186 karma points
    Jan 14, 2022 @ 14:51
    ReneRam
    0

    Sitemap Builder

    Hi. I'm implementing sitemap.xml update/rebuild when the Editor presses "Save and Publish" or "Publish" if document is Draft.

    My code works and writes the file in the specified directory, but the document is added only if user publishes twice. On the first Save and Publish I get the new sitemap.xml without the new document, on the second Save and Publish it's added.

    I have tried following the documentation and writing my code in:

    • SubscribeToContentServiceSavingComponent : IComponent
    • private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e) {...}

    • SubscribeToPublishEventComponent : IComponent

    • private void ContentService_Publishing(Umbraco.Core.Services.IContentService sender, Umbraco.Core.Events.ContentPublishingEventArgs e) {...}

    But I get the same result. what am I doing wrong?

    Thanks in advance

  • Kevin Jump 2341 posts 14868 karma points MVP 8x c-trib
    Jan 14, 2022 @ 15:29
    Kevin Jump
    2

    Hi Rene,

    I think you should look at using the Saved and Published version of those events e.g

    ContentService.Saved += ContentService_Saved
    ContentService.Published += ContentService_Published
    

    the Saving and Publishing events are fired before Umbraco has done the work (they are so you can intervene maybe stop or alter things before they are done) where as saved and published happen after when everything is in the cache live on the site.

  • ReneRam 21 posts 186 karma points
    Jan 15, 2022 @ 15:28
    ReneRam
    100

    Thanks Kevin, that was the problem!

Please Sign in or register to post replies

Write your reply to:

Draft