Copied to clipboard

Flag this post as spam?

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


  • J.A. Utsi 1 post 21 karma points
    May 04, 2010 @ 12:26
    J.A. Utsi
    0

    Can't publish a new DocB from DocA's AfterPublish event

    I have a document DocA that is created on user interaction.
    DocA has a child document DocB that is created on the AfterPublish event for DocA.
    My problem is that DocB doesn't get published, I've tried to catch the AfterSave event for DocA instead .. without luck.

    What is the proper way of creating a child document during creation/publish using events?

    This is how I try to do this:

    public static void CreateDocA(string pageName, int parentId)
    {
    DocumentType dt = DocumentType.GetByAlias(DocA_Alias);
    Document docA = Document.MakeNew(pageName, dt, User.GetUser(0), parentId);
    docA.Save();
    docA.Publish(User.GetUser(0));
    umbraco.library.UpdateDocumentCache(docA.Id);
    }
    void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e)
    {
        if (sender.ContentType.Alias.Equals(DocA_Alias))
        {
            foreach (Document d in sender.Children)
            {
    if (d.ContentType.Alias.Equals(DocB_Alias))
                    return;
            }
            DocumentType dt = DocumentType.GetByAlias(DocB_Alias);
            Document docB = Document.MakeNew(sender.Text, dt, User.GetUser(0), sender.Id);
            docB.Save();
            docB.Publish(User.GetUser(0));
            umbraco.library.UpdateDocumentCache(docB.Id);
        }           
    }

     

    /j

Please Sign in or register to post replies

Write your reply to:

Draft