Copied to clipboard

Flag this post as spam?

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


  • deldongdong 11 posts 26 karma points
    Mar 15, 2012 @ 04:14
    deldongdong
    0

    how to publish with all unpublished sub nodes?

    i found that publishWithSubs method just can publish first level nodes of the parent node.

    how can i publish all the unpublished nodes under one parent node? no matter how deepth the unpublished nodes are.

     

    Thanks

  • Ian Robinson 79 posts 143 karma points
    Mar 15, 2012 @ 17:19
    Ian Robinson
    0

    I'm not familiar with the "publishWithSubs" method but could you loop through the children of the parent document instead and recursively publish every child document?  

    I say "Document" instead of "Node" because I think only a document can be published, a node is already a published version of the underlying document, see http://our.umbraco.org/wiki/reference/api-cheatsheet/difference-between-node-and-document.

    For example you could have a method that calls itself, once you call it initially on your parent document.  Something like:

    // get a document version of your node
    Document parentDoc = new Document(node.Id);

    // where parentDoc is your parent Document
    this.PublishChildDocs(parentDoc);
    protected void PublishChildDocs(Document doc)
    {
             doc.Publish(User.GetUser(0));
                
             // loop through all child documents in the doc, recursively calling this method
             foreach (Document childDoc in doc.Children)
             {
                    PublishChildDocs(childDoc);
             }
    
     }
    

     

     

  • Rodion Novoselov 694 posts 859 karma points
    Mar 15, 2012 @ 20:52
    Rodion Novoselov
    0

    Hi. Probably this will work:

    doc.PublishWithSubs(User.GetCurrent());
    library.RefreshContent(); 

    Some drawback may be that the whole umbraco.config will be rebuilt, though.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies