Copied to clipboard

Flag this post as spam?

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


  • Stefan Beyer 3 posts 23 karma points
    Apr 08, 2013 @ 08:41
    Stefan Beyer
    0

    Document.Copy() without copying child documents

    Let's assume we have a simple structure for our content, e.g.: 

    home
    --products
    ----product 1
    ----product 2
    --services
    --about us
    --...

     

    Trying to copy "home" using Document.Copy() works fine, but also copies all child documents, which is something I do not want. Is there any way to "ignore" childen when copying?

    I would have expected some optional parameter for Document.Copy() that enables / disables recursion, but there seems to be none.

    Umbraco 4.11

     

  • Sahan Rodrigo 25 posts 97 karma points
    Apr 08, 2013 @ 10:15
    Sahan Rodrigo
    0

    Hi Stefan,

    I had the same issue few months back, coudn't able to find any solution yet, always had to delete children of newly created document. 

     

    if (newDoc.ChildCount > 0)

     {

            foreach (var childDocs in newDoc.Children)

            {

                         childDocs.delete(true);

             }

      }

    It would be nice if anyone from forum can help on this.

    Thanks

    Sahan

     

  • Stefan Beyer 3 posts 23 karma points
    Apr 08, 2013 @ 10:31
    Stefan Beyer
    0

    Hello Sahan

    yes, his making-a-mess-and-cleaning-up-again-in-two-easy-steps ;-)), came to my mind, too. But: If I want to copy Home AND products (one level below Home) but I do not want to copy "services" and "about us", this approach is gettings *really* messy ...

    It would be nice if anyone from forum can help on this!

    Stefan

  • Stefan Beyer 3 posts 23 karma points
    Apr 29, 2013 @ 09:22
    Stefan Beyer
    0

    Seems as if there is nobody out there to help ... ?

     

    Ok, what I did is ... : 

     

    - Got the sourcecode for Umbraco 4.11...

     

    - Went to umbraco.cms.businesslogic.web.Document

     

    - introduced a 4th paramter for Copy(): bool CopyChildren 

    public Document Copy(int CopyTo, User u, bool RelateToOrignal, bool CopyChildren) { ... }

     

    - Somewhere at the end of the method there is a recursive call to copy all children. Using the new paramter CopyChildren changed this fragment as follows: 

    if (CopyChildren) { 
    (...)
    d.Copy(newDoc.Id, u, RelateToOrignal, true);
    (...)
    }

     

    - introduced a new method with the signature of the "old" Copy-method so that I don't break any existing functionality / tests: 

    public Document Copy(int CopyTo, User u, bool RelateToOrignal) {
    return this.Copy(CopyTo, u, RelateToOrignal, true);
    }
    This is it.
    Standard behaviour for Document.Copy() copies all child documents, a new method with a 4th paramter which specifies, if child documents should be copied, is also available so that rare cases like mine can also be implemented.
    I have no idea how to submit this code back to the umbraco-repository, but I will try to find out ...

     

  • CASTELLI 23 posts 76 karma points
    Sep 16, 2013 @ 16:29
    CASTELLI
    0

    Hi,

    I have the same problem and applied the solution proposed above, except that I'm using Umbraco V6.

    More détails in http://our.umbraco.org/forum/developers/extending-umbraco/44763-using-DocumentCopy-to-move-a-page-keeping-the-tree-structure

  • 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