Copied to clipboard

Flag this post as spam?

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


  • Thomas 315 posts 602 karma points c-trib
    Jun 26, 2019 @ 13:25
    Thomas
    0

    Create new page event

    Hey :)

    Is it possible to hit the new page created event. I want to create som subpage when a root page has been created.

    I have this right now, and I don't think that's the way to go

    public class ContentServiceSavingComponent : IComponent
    {
        // initialize: runs once when Umbraco starts
        public void Initialize()
        {
            ContentService.Saving += ContentService_Saving;
        }
    
        // terminate: runs once when Umbraco stops
        public void Terminate()
        {
        }
    
        private void ContentService_Saving(IContentService sender, ContentSavingEventArgs e)
        {
            foreach (var root in e.SavedEntities
                //Check if the content item type has a specific alias
                .Where(c => c.ContentType.Alias.InvariantEquals("Frontpage")))
            {
                if (root.Id == 0)
                {
                    var udi = new GuidUdi("document", root.Key);
                    ContentService.CreateAndSave("FROM CODE", root.Id, "libraryFolder");
    
                }
    
                //Do something if the content is using the MyContentType doctype
            }
        }
    }
    

    I will only do this when a new page is created. Hope any one can help!

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft