Copied to clipboard

Flag this post as spam?

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

  • ReneRam 16 posts 121 karma points
    1 week ago

    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 2031 posts 12829 karma points MVP 5x c-trib
    1 week ago
    Kevin Jump

    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 16 posts 121 karma points
    1 week ago

    Thanks Kevin, that was the problem!

Please Sign in or register to post replies

Write your reply to: